Auto merge of #54942 - matthewjasper:wf-type-annotations, r=nikomatsakis
[NLL] Check user types are well-formed Also contains a change of span for AscribeUserType. I'm not quite sure if this was what @nikomatsakis was thinking. Closes #54620 r? @nikomatsakis
This commit is contained in:
commit
2c2e2c57dc
42 changed files with 344 additions and 135 deletions
|
|
@ -0,0 +1,24 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/associated-types-subtyping-1.rs:36:13
|
||||
|
|
||||
LL | fn method2<'a,'b,T>(x: &'a T, y: &'b T)
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let _c: <T as Trait<'b>>::Type = a; //~ ERROR E0623
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/associated-types-subtyping-1.rs:44:12
|
||||
|
|
||||
LL | fn method3<'a,'b,T>(x: &'a T, y: &'b T)
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let b: <T as Trait<'b>>::Type = make_any();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -8,10 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn make_any<T>() -> T { loop {} }
|
||||
|
||||
trait Trait<'a> {
|
||||
type Type;
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ fn method1<'a,'b,T>(x: &'a T, y: &'b T)
|
|||
where T : for<'z> Trait<'z>, 'a : 'b
|
||||
{
|
||||
// Note that &'static T <: &'a T.
|
||||
let a: <T as Trait<'a>>::Type = loop { };
|
||||
let b: <T as Trait<'b>>::Type = loop { };
|
||||
let a: <T as Trait<'a>>::Type = make_any();
|
||||
let b: <T as Trait<'b>>::Type = make_any();
|
||||
let _c: <T as Trait<'a>>::Type = a;
|
||||
}
|
||||
|
||||
|
|
@ -31,8 +31,8 @@ fn method2<'a,'b,T>(x: &'a T, y: &'b T)
|
|||
where T : for<'z> Trait<'z>, 'a : 'b
|
||||
{
|
||||
// Note that &'static T <: &'a T.
|
||||
let a: <T as Trait<'a>>::Type = loop { };
|
||||
let b: <T as Trait<'b>>::Type = loop { };
|
||||
let a: <T as Trait<'a>>::Type = make_any();
|
||||
let b: <T as Trait<'b>>::Type = make_any();
|
||||
let _c: <T as Trait<'b>>::Type = a; //~ ERROR E0623
|
||||
}
|
||||
|
||||
|
|
@ -40,8 +40,8 @@ fn method3<'a,'b,T>(x: &'a T, y: &'b T)
|
|||
where T : for<'z> Trait<'z>, 'a : 'b
|
||||
{
|
||||
// Note that &'static T <: &'a T.
|
||||
let a: <T as Trait<'a>>::Type = loop { };
|
||||
let b: <T as Trait<'b>>::Type = loop { };
|
||||
let a: <T as Trait<'a>>::Type = make_any();
|
||||
let b: <T as Trait<'b>>::Type = make_any();
|
||||
let _c: <T as Trait<'a>>::Type = b; //~ ERROR E0623
|
||||
}
|
||||
|
||||
|
|
@ -49,8 +49,8 @@ fn method4<'a,'b,T>(x: &'a T, y: &'b T)
|
|||
where T : for<'z> Trait<'z>, 'a : 'b
|
||||
{
|
||||
// Note that &'static T <: &'a T.
|
||||
let a: <T as Trait<'a>>::Type = loop { };
|
||||
let b: <T as Trait<'b>>::Type = loop { };
|
||||
let a: <T as Trait<'a>>::Type = make_any();
|
||||
let b: <T as Trait<'b>>::Type = make_any();
|
||||
let _c: <T as Trait<'b>>::Type = b;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ LL | let a: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
|
|||
| ^^^^^^^^^
|
||||
|
||||
error: higher-ranked subtype error
|
||||
--> $DIR/hr-fn-aaa-as-aba.rs:32:9
|
||||
--> $DIR/hr-fn-aaa-as-aba.rs:32:12
|
||||
|
|
||||
LL | let _: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
|
||||
| ^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -131,12 +131,12 @@ LL | y //~ ERROR
|
|||
| ^ returning this value requires that `'a` must outlive `'static`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/patterns.rs:117:9
|
||||
--> $DIR/patterns.rs:117:18
|
||||
|
|
||||
LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
|
||||
| -- lifetime `'a` defined here
|
||||
LL | let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
|
||||
| ^^^^^^^ type annotation requires that `'a` must outlive `'static`
|
||||
| ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0621]: explicit lifetime required in the type of `v`
|
||||
--> $DIR/region-object-lifetime-in-coercion.rs:18:9
|
||||
--> $DIR/region-object-lifetime-in-coercion.rs:18:12
|
||||
|
|
||||
LL | fn a(v: &[u8]) -> Box<Foo + 'static> {
|
||||
| ----- help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
|
||||
LL | let x: Box<Foo + 'static> = Box::new(v);
|
||||
| ^ lifetime `'static` required
|
||||
| ^^^^^^^^^^^^^^^^^^ lifetime `'static` required
|
||||
|
||||
error[E0621]: explicit lifetime required in the type of `v`
|
||||
--> $DIR/region-object-lifetime-in-coercion.rs:24:5
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-addr-of-self.rs:17:13
|
||||
--> $DIR/regions-addr-of-self.rs:17:16
|
||||
|
|
||||
LL | pub fn chase_cat(&mut self) {
|
||||
| - let's call the lifetime of this reference `'1`
|
||||
LL | let p: &'static mut usize = &mut self.cats_chased; //~ ERROR cannot infer
|
||||
| ^ type annotation requires that `'1` must outlive `'static`
|
||||
| ^^^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:17
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:20
|
||||
|
|
||||
LL | let _f = || {
|
||||
| -- lifetime `'1` represents this closure's body
|
||||
LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
|
||||
| ^ type annotation requires that `'1` must outlive `'static`
|
||||
| ^^^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static`
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:17
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:20
|
||||
|
|
||||
LL | pub fn chase_cat(&mut self) {
|
||||
| --------- lifetime `'2` appears in the type of `self`
|
||||
LL | let _f = || {
|
||||
| -- lifetime `'1` represents this closure's body
|
||||
LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
|
||||
| ^ type annotation requires that `'1` must outlive `'2`
|
||||
| ^^^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'2`
|
||||
|
|
||||
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:17
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:20
|
||||
|
|
||||
LL | pub fn chase_cat(&mut self) {
|
||||
| - let's call the lifetime of this reference `'1`
|
||||
LL | let _f = || {
|
||||
LL | let p: &'static mut usize = &mut self.food; //~ ERROR cannot infer
|
||||
| ^ type annotation requires that `'1` must outlive `'static`
|
||||
| ^^^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static`
|
||||
|
||||
error[E0597]: `self` does not live long enough
|
||||
--> $DIR/regions-addr-of-upvar-self.rs:20:46
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:52:13
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
// Test that we are imposing the requirement that every associated
|
||||
// type of a bound that appears in the where clause on a struct must
|
||||
// outlive the location in which the type appears, even when the
|
||||
|
|
@ -49,7 +47,10 @@ fn with_assoc<'a,'b>() {
|
|||
// outlive 'a. In this case, that means TheType<'b>::TheAssocType,
|
||||
// which is &'b (), must outlive 'a.
|
||||
|
||||
let _: &'a WithAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime
|
||||
// FIXME (#54943) NLL doesn't enforce WF condition in unreachable code if
|
||||
// `_x` is changed to `_`
|
||||
let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
//~^ ERROR reference has a longer lifetime
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:52:12
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:52:13
|
||||
|
|
||||
LL | let _: &'a WithAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 46:15
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:46:15
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 44:15
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:44:15
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 46:18
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:46:18
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 44:18
|
||||
--> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:44:18
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:18:12
|
||||
|
|
||||
LL | fn call2<'a, 'b>(a: &'a usize, b: &'b usize) {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
LL | let z: Option<&'b &'a usize> = None;//~ ERROR E0623
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'b`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:23:12
|
||||
|
|
||||
LL | fn call3<'a, 'b>(a: &'a usize, b: &'b usize) {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
LL | let y: Paramd<'a> = Paramd { x: a };
|
||||
LL | let z: Option<&'b Paramd<'a>> = None;//~ ERROR E0623
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'b`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:27:12
|
||||
|
|
||||
LL | fn call4<'a, 'b>(a: &'a usize, b: &'b usize) {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
LL | let z: Option<&'a &'b usize> = None;//~ ERROR E0623
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
// Test various ways to construct a pointer with a longer lifetime
|
||||
// than the thing it points at and ensure that they result in
|
||||
// errors. See also regions-free-region-ordering-callee.rs
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0623]: lifetime mismatch
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:20:12
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:18:12
|
||||
|
|
||||
LL | fn call2<'a, 'b>(a: &'a usize, b: &'b usize) {
|
||||
| --------- ---------
|
||||
|
|
@ -9,7 +9,7 @@ LL | let z: Option<&'b &'a usize> = None;//~ ERROR E0623
|
|||
| ^^^^^^^^^^^^^^^^^^^^^ ...but data from `a` flows into `b` here
|
||||
|
||||
error[E0623]: lifetime mismatch
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:25:12
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:23:12
|
||||
|
|
||||
LL | fn call3<'a, 'b>(a: &'a usize, b: &'b usize) {
|
||||
| --------- ---------
|
||||
|
|
@ -20,7 +20,7 @@ LL | let z: Option<&'b Paramd<'a>> = None;//~ ERROR E0623
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^ ...but data from `a` flows into `b` here
|
||||
|
||||
error[E0623]: lifetime mismatch
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:29:12
|
||||
--> $DIR/regions-free-region-ordering-caller.rs:27:12
|
||||
|
|
||||
LL | fn call4<'a, 'b>(a: &'a usize, b: &'b usize) {
|
||||
| --------- --------- these two types are declared with different lifetimes...
|
||||
|
|
|
|||
|
|
@ -13,6 +13,22 @@ note: borrowed value must be valid for the lifetime 'a as defined on the functio
|
|||
LL | fn call1<'a>(x: &'a usize) {
|
||||
| ^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0597]: `y` does not live long enough
|
||||
--> $DIR/regions-free-region-ordering-caller1.rs:19:27
|
||||
|
|
||||
LL | let z: &'a & usize = &(&y);
|
||||
| ^^^^ borrowed value does not live long enough
|
||||
...
|
||||
LL | }
|
||||
| - `y` dropped here while still borrowed
|
||||
|
|
||||
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 15:10...
|
||||
--> $DIR/regions-free-region-ordering-caller1.rs:15:10
|
||||
|
|
||||
LL | fn call1<'a>(x: &'a usize) {
|
||||
| ^^
|
||||
|
||||
For more information about this error, try `rustc --explain E0716`.
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors occurred: E0597, E0716.
|
||||
For more information about an error, try `rustc --explain E0597`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/regions-implied-bounds-projection-gap-1.rs:26:5
|
||||
|
|
||||
LL | wf::<&'x T>();
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding an explicit lifetime bound `T: 'x`...
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0309`.
|
||||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
// Illustrates the "projection gap": in this test, even though we know
|
||||
// that `T::Foo: 'x`, that does not tell us that `T: 'x`, because
|
||||
// there might be other ways for the caller of `func` to show that
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/regions-implied-bounds-projection-gap-1.rs:28:10
|
||||
--> $DIR/regions-implied-bounds-projection-gap-1.rs:26:10
|
||||
|
|
||||
LL | fn func<'x, T:Trait1<'x>>(t: &'x T::Foo)
|
||||
| -- help: consider adding an explicit lifetime bound `T: 'x`...
|
||||
|
|
@ -8,7 +8,7 @@ LL | wf::<&'x T>();
|
|||
| ^^^^^
|
||||
|
|
||||
note: ...so that the reference type `&'x T` does not outlive the data it points at
|
||||
--> $DIR/regions-implied-bounds-projection-gap-1.rs:28:10
|
||||
--> $DIR/regions-implied-bounds-projection-gap-1.rs:26:10
|
||||
|
|
||||
LL | wf::<&'x T>();
|
||||
| ^^^^^
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-infer-contravariance-due-to-decl.rs:35:9
|
||||
--> $DIR/regions-infer-contravariance-due-to-decl.rs:35:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: Contravariant<'short>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: Contravariant<'short>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: Contravariant<'long> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-infer-covariance-due-to-decl.rs:32:9
|
||||
--> $DIR/regions-infer-covariance-due-to-decl.rs:32:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: Covariant<'long>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: Covariant<'long>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: Covariant<'short> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:46:13
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
// Test that we are imposing the requirement that every associated
|
||||
// type of a bound that appears in the where clause on a struct must
|
||||
// outlive the location in which the type appears, even when the
|
||||
|
|
@ -43,7 +41,9 @@ fn with_assoc<'a,'b>() {
|
|||
// outlive 'a. In this case, that means TheType<'b>::TheAssocType,
|
||||
// which is &'b (), must outlive 'a.
|
||||
|
||||
let _: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
// FIXME (#54943) NLL doesn't enforce WF condition in unreachable code if
|
||||
// `_x` is changed to `_`
|
||||
let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
//~^ ERROR reference has a longer lifetime
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:46:12
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:46:13
|
||||
|
|
||||
LL | let _: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 40:15
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:40:15
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 38:15
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:38:15
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 40:18
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:40:18
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 38:18
|
||||
--> $DIR/regions-outlives-projection-container-wc.rs:38:18
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-outlives-projection-container.rs:50:13
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-outlives-projection-container.rs:68:13
|
||||
|
|
||||
LL | fn without_assoc<'a,'b>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let _x: &'a WithoutAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-outlives-projection-container.rs:77:5
|
||||
|
|
||||
LL | fn call_with_assoc<'a,'b>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | call::<&'a WithAssoc<TheType<'b>>>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-outlives-projection-container.rs:84:5
|
||||
|
|
||||
LL | fn call_without_assoc<'a,'b>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | call::<&'a WithoutAssoc<TheType<'b>>>(); //~ ERROR reference has a longer lifetime
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-compare-mode-nll
|
||||
|
||||
// Test that we are imposing the requirement that every associated
|
||||
// type of a bound that appears in the where clause on a struct must
|
||||
// outlive the location in which the type appears. Issue #22246.
|
||||
|
|
@ -47,7 +45,10 @@ fn with_assoc<'a,'b>() {
|
|||
// outlive 'a. In this case, that means TheType<'b>::TheAssocType,
|
||||
// which is &'b (), must outlive 'a.
|
||||
|
||||
let _: &'a WithAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime
|
||||
// FIXME (#54943) NLL doesn't enforce WF condition in unreachable code if
|
||||
// `_x` is changed to `_`
|
||||
let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
//~^ ERROR reference has a longer lifetime
|
||||
}
|
||||
|
||||
fn with_assoc1<'a,'b>() where 'b : 'a {
|
||||
|
|
@ -57,14 +58,15 @@ fn with_assoc1<'a,'b>() where 'b : 'a {
|
|||
// which is &'b (), must outlive 'a, so 'b : 'a must hold, and
|
||||
// that is in the where clauses, so we're fine.
|
||||
|
||||
let _: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
}
|
||||
|
||||
fn without_assoc<'a,'b>() {
|
||||
// Here there are no associated types but there is a requirement
|
||||
// that `'b:'a` holds because the `'b` appears in `TheType<'b>`.
|
||||
|
||||
let _: &'a WithoutAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime
|
||||
let _x: &'a WithoutAssoc<TheType<'b>> = loop { };
|
||||
//~^ ERROR reference has a longer lifetime
|
||||
}
|
||||
|
||||
fn call_with_assoc<'a,'b>() {
|
||||
|
|
|
|||
|
|
@ -1,67 +1,67 @@
|
|||
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-projection-container.rs:50:12
|
||||
--> $DIR/regions-outlives-projection-container.rs:50:13
|
||||
|
|
||||
LL | let _: &'a WithAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 44:15
|
||||
--> $DIR/regions-outlives-projection-container.rs:44:15
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 42:15
|
||||
--> $DIR/regions-outlives-projection-container.rs:42:15
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 44:18
|
||||
--> $DIR/regions-outlives-projection-container.rs:44:18
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 42:18
|
||||
--> $DIR/regions-outlives-projection-container.rs:42:18
|
||||
|
|
||||
LL | fn with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
|
||||
error[E0491]: in type `&'a WithoutAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-projection-container.rs:67:12
|
||||
--> $DIR/regions-outlives-projection-container.rs:68:13
|
||||
|
|
||||
LL | let _: &'a WithoutAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let _x: &'a WithoutAssoc<TheType<'b>> = loop { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 63:18
|
||||
--> $DIR/regions-outlives-projection-container.rs:63:18
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 64:18
|
||||
--> $DIR/regions-outlives-projection-container.rs:64:18
|
||||
|
|
||||
LL | fn without_assoc<'a,'b>() {
|
||||
| ^^
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 63:21
|
||||
--> $DIR/regions-outlives-projection-container.rs:63:21
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 64:21
|
||||
--> $DIR/regions-outlives-projection-container.rs:64:21
|
||||
|
|
||||
LL | fn without_assoc<'a,'b>() {
|
||||
| ^^
|
||||
|
||||
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-projection-container.rs:75:12
|
||||
--> $DIR/regions-outlives-projection-container.rs:77:12
|
||||
|
|
||||
LL | call::<&'a WithAssoc<TheType<'b>>>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 70:20
|
||||
--> $DIR/regions-outlives-projection-container.rs:70:20
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 72:20
|
||||
--> $DIR/regions-outlives-projection-container.rs:72:20
|
||||
|
|
||||
LL | fn call_with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 70:23
|
||||
--> $DIR/regions-outlives-projection-container.rs:70:23
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 72:23
|
||||
--> $DIR/regions-outlives-projection-container.rs:72:23
|
||||
|
|
||||
LL | fn call_with_assoc<'a,'b>() {
|
||||
| ^^
|
||||
|
||||
error[E0491]: in type `&'a WithoutAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-projection-container.rs:82:12
|
||||
--> $DIR/regions-outlives-projection-container.rs:84:12
|
||||
|
|
||||
LL | call::<&'a WithoutAssoc<TheType<'b>>>(); //~ ERROR reference has a longer lifetime
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 79:23
|
||||
--> $DIR/regions-outlives-projection-container.rs:79:23
|
||||
note: the pointer is valid for the lifetime 'a as defined on the function body at 81:23
|
||||
--> $DIR/regions-outlives-projection-container.rs:81:23
|
||||
|
|
||||
LL | fn call_without_assoc<'a,'b>() {
|
||||
| ^^
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 79:26
|
||||
--> $DIR/regions-outlives-projection-container.rs:79:26
|
||||
note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 81:26
|
||||
--> $DIR/regions-outlives-projection-container.rs:81:26
|
||||
|
|
||||
LL | fn call_without_assoc<'a,'b>() {
|
||||
| ^^
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-variance-contravariant-use-covariant-in-second-position.rs:35:9
|
||||
--> $DIR/regions-variance-contravariant-use-covariant-in-second-position.rs:35:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: S<'long, 'short>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: S<'long, 'short>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: S<'long, 'long> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-variance-contravariant-use-covariant.rs:33:9
|
||||
--> $DIR/regions-variance-contravariant-use-covariant.rs:33:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: Contravariant<'short>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: Contravariant<'short>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: Contravariant<'long> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-variance-covariant-use-contravariant.rs:33:9
|
||||
--> $DIR/regions-variance-covariant-use-contravariant.rs:33:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: Covariant<'long>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: Covariant<'long>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: Covariant<'short> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-variance-invariant-use-contravariant.rs:30:9
|
||||
--> $DIR/regions-variance-invariant-use-contravariant.rs:30:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: Invariant<'long>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: Invariant<'long>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: Invariant<'short> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/regions-variance-invariant-use-covariant.rs:27:9
|
||||
--> $DIR/regions-variance-invariant-use-covariant.rs:27:12
|
||||
|
|
||||
LL | fn use_<'b>(c: Invariant<'b>) {
|
||||
| -- lifetime `'b` defined here
|
||||
...
|
||||
LL | let _: Invariant<'static> = c; //~ ERROR mismatched types
|
||||
| ^ type annotation requires that `'b` must outlive `'static`
|
||||
| ^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'static`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0597]: `my_string` does not live long enough
|
|||
--> $DIR/try-block-bad-lifetime.rs:25:33
|
||||
|
|
||||
LL | let result: Result<(), &str> = try {
|
||||
| ------ borrow later used here
|
||||
| ------ borrow later stored here
|
||||
LL | let my_string = String::from("");
|
||||
LL | let my_str: & str = & my_string;
|
||||
| ^^^^^^^^^^^ borrowed value does not live long enough
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/variance-cell-is-invariant.rs:24:9
|
||||
--> $DIR/variance-cell-is-invariant.rs:24:12
|
||||
|
|
||||
LL | fn use_<'short,'long>(c: Foo<'short>,
|
||||
| ------ ----- lifetime `'long` defined here
|
||||
|
|
@ -7,7 +7,7 @@ LL | fn use_<'short,'long>(c: Foo<'short>,
|
|||
| lifetime `'short` defined here
|
||||
...
|
||||
LL | let _: Foo<'long> = c; //~ ERROR E0623
|
||||
| ^ type annotation requires that `'short` must outlive `'long`
|
||||
| ^^^^^^^^^^ type annotation requires that `'short` must outlive `'long`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,17 @@ LL | impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () {
|
|||
LL | u //~ ERROR E0312
|
||||
| ^ returning this value requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/wf-static-method.rs:36:18
|
||||
|
|
||||
LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | let me = Self::make_me(); //~ ERROR lifetime bound not satisfied
|
||||
| ^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/wf-static-method.rs:43:9
|
||||
|
|
||||
|
|
@ -20,5 +31,25 @@ LL | fn inherent_evil(u: &'b u32) -> &'a u32 {
|
|||
LL | u //~ ERROR E0312
|
||||
| ^ returning this value requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/wf-static-method.rs:51:5
|
||||
|
|
||||
LL | fn evil<'a, 'b>(b: &'b u32) -> &'a u32 {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
LL | <()>::static_evil(b) //~ ERROR cannot infer an appropriate lifetime
|
||||
| ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'b` must outlive `'a`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/wf-static-method.rs:55:5
|
||||
|
|
||||
LL | fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
LL | <IndirectEvil>::static_evil(b)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'b` must outlive `'a`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue