diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 6d152fc87bd33bbda96a5bf8e8de204ad5a8c2c1..182e31a77b1b4d4dd020cd45b2a6feb4528ac4d4 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1033,6 +1033,8 @@ fn relate_type_and_user_type( 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`. diff --git a/src/test/ui/issues/issue-28848.rs b/src/test/ui/issues/issue-28848.rs index c13fd5fa71669e9444b8314246f0dded9f3eb19a..1a06d59f0b191a22ba5fb15de4f21670058280f3 100644 --- a/src/test/ui/issues/issue-28848.rs +++ b/src/test/ui/issues/issue-28848.rs @@ -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> { diff --git a/src/test/ui/issues/issue-28848.stderr b/src/test/ui/issues/issue-28848.stderr index dadcff226f53bc7439d47b67534c83cc608bd82f..738a1c0c6f616bff65c3944eb117f41c234ee3c7 100644 --- a/src/test/ui/issues/issue-28848.stderr +++ b/src/test/ui/issues/issue-28848.stderr @@ -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 () { | ^^ diff --git a/src/test/ui/nll/user-annotations/wf-self-type.rs b/src/test/ui/nll/user-annotations/wf-self-type.rs new file mode 100644 index 0000000000000000000000000000000000000000..c3cb3068bcecf3533b483a30adee2356d5c7ef5d --- /dev/null +++ b/src/test/ui/nll/user-annotations/wf-self-type.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/ui/nll/user-annotations/wf-self-type.stderr b/src/test/ui/nll/user-annotations/wf-self-type.stderr new file mode 100644 index 0000000000000000000000000000000000000000..78d86fbf17ec09706fada4d301eac0fe836f1031 --- /dev/null +++ b/src/test/ui/nll/user-annotations/wf-self-type.stderr @@ -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 +