1
Fork 0

check the self type is well-formed

This fixes `issue-28848.rs` -- it also handles another case that the
AST region checker gets wrong (`wf-self-type.rs`).  I don't actually
think that this is the *right way* to be enforcing this constraint --
I think we should probably do it more generally, perhaps by editing
`predicates_of` for the impl itself. The chalk-style implied bounds
setup ought to fix this.
This commit is contained in:
Niko Matsakis 2018-10-23 10:30:41 -04:00
parent 64b5599352
commit 1371cd27d0
5 changed files with 44 additions and 7 deletions

View file

@ -1033,6 +1033,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
assert!(!impl_self_ty.has_infer_types());
self.eq_types(self_ty, impl_self_ty, locations, category)?;
self.prove_predicate(ty::Predicate::WellFormed(impl_self_ty), locations, category);
}
// Prove the predicates coming along with `def_id`.

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
struct Foo<'a, 'b: 'a>(&'a &'b ());
impl<'a, 'b> Foo<'a, 'b> {

View file

@ -1,16 +1,16 @@
error[E0478]: lifetime bound not satisfied
--> $DIR/issue-28848.rs:22:5
--> $DIR/issue-28848.rs:20:5
|
LL | Foo::<'a, 'b>::xmute(u) //~ ERROR lifetime bound not satisfied
| ^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime 'b as defined on the function body at 21:16
--> $DIR/issue-28848.rs:21:16
note: lifetime parameter instantiated with the lifetime 'b as defined on the function body at 19:16
--> $DIR/issue-28848.rs:19:16
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| ^^
note: but lifetime parameter must outlive the lifetime 'a as defined on the function body at 21:12
--> $DIR/issue-28848.rs:21:12
note: but lifetime parameter must outlive the lifetime 'a as defined on the function body at 19:12
--> $DIR/issue-28848.rs:19:12
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| ^^

View file

@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(nll)]
struct Foo<'a, 'b: 'a>(&'a &'b ());
impl<'a, 'b> Foo<'a, 'b> {
fn xmute(a: &'b ()) -> &'a () {
unreachable!()
}
}
pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
Foo::xmute(u) //~ ERROR unsatisfied lifetime constraints
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: unsatisfied lifetime constraints
--> $DIR/wf-self-type.rs:22:5
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | Foo::xmute(u) //~ ERROR unsatisfied lifetime constraints
| ^^^^^^^^^^^^^ returning this value requires that `'b` must outlive `'a`
error: aborting due to previous error