1
Fork 0

Use revisions for NLL in object-lifetime

This commit is contained in:
Jack Huey 2022-05-21 14:45:57 -04:00
commit 99daba2a4a
15 changed files with 67 additions and 35 deletions

View file

@ -1,26 +1,26 @@
error[E0495]: cannot infer an appropriate lifetime for automatic coercion due to conflicting requirements error[E0495]: cannot infer an appropriate lifetime for automatic coercion due to conflicting requirements
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | ss LL | ss
| ^^ | ^^
| |
note: first, the lifetime cannot outlive the lifetime `'a` as defined here... note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
--> $DIR/object-lifetime-default-elision.rs:54:10 --> $DIR/object-lifetime-default-elision.rs:58:10
| |
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| ^^ | ^^
note: ...so that reference does not outlive borrowed content note: ...so that reference does not outlive borrowed content
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | ss LL | ss
| ^^ | ^^
note: but, the lifetime must be valid for the lifetime `'b` as defined here... note: but, the lifetime must be valid for the lifetime `'b` as defined here...
--> $DIR/object-lifetime-default-elision.rs:54:13 --> $DIR/object-lifetime-default-elision.rs:58:13
| |
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| ^^ | ^^
note: ...so that the types are compatible note: ...so that the types are compatible
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | ss LL | ss
| ^^ | ^^
@ -28,28 +28,28 @@ LL | ss
found `&dyn SomeTrait` found `&dyn SomeTrait`
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | ss LL | ss
| ^^ | ^^
| |
note: first, the lifetime cannot outlive the lifetime `'a` as defined here... note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
--> $DIR/object-lifetime-default-elision.rs:54:10 --> $DIR/object-lifetime-default-elision.rs:58:10
| |
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| ^^ | ^^
note: ...so that the declared lifetime parameter bounds are satisfied note: ...so that the declared lifetime parameter bounds are satisfied
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | ss LL | ss
| ^^ | ^^
note: but, the lifetime must be valid for the lifetime `'b` as defined here... note: but, the lifetime must be valid for the lifetime `'b` as defined here...
--> $DIR/object-lifetime-default-elision.rs:54:13 --> $DIR/object-lifetime-default-elision.rs:58:13
| |
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| ^^ | ^^
note: ...so that the types are compatible note: ...so that the types are compatible
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | ss LL | ss
| ^^ | ^^

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/object-lifetime-default-elision.rs:71:5 --> $DIR/object-lifetime-default-elision.rs:75:5
| |
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| -- -- lifetime `'b` defined here | -- -- lifetime `'b` defined here

View file

@ -1,3 +1,7 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
// Test various cases where the old rules under lifetime elision // Test various cases where the old rules under lifetime elision
// yield slightly different results than the new rules. // yield slightly different results than the new rules.
@ -69,8 +73,9 @@ fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
// which fails to type check. // which fails to type check.
ss ss
//~^ ERROR cannot infer //[base]~^ ERROR cannot infer
//~| ERROR cannot infer //[base]~| ERROR cannot infer
//[nll]~^^^ ERROR lifetime may not live long enough
} }
fn main() { fn main() {

View file

@ -1,5 +1,5 @@
error[E0759]: `ss` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement error[E0759]: `ss` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/object-lifetime-default-from-box-error.rs:18:5 --> $DIR/object-lifetime-default-from-box-error.rs:22:5
| |
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> { LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
| --------------- this data with an anonymous lifetime `'_`... | --------------- this data with an anonymous lifetime `'_`...
@ -8,7 +8,7 @@ LL | ss.r
| ^^^^ ...is used and required to live as long as `'static` here | ^^^^ ...is used and required to live as long as `'static` here
| |
note: `'static` lifetime requirement introduced by the return type note: `'static` lifetime requirement introduced by the return type
--> $DIR/object-lifetime-default-from-box-error.rs:14:37 --> $DIR/object-lifetime-default-from-box-error.rs:18:37
| |
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> { LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
| ^^^^^^^^^^^^^ `'static` requirement introduced here | ^^^^^^^^^^^^^ `'static` requirement introduced here
@ -21,7 +21,7 @@ LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
| ++++ | ++++
error[E0621]: explicit lifetime required in the type of `ss` error[E0621]: explicit lifetime required in the type of `ss`
--> $DIR/object-lifetime-default-from-box-error.rs:31:12 --> $DIR/object-lifetime-default-from-box-error.rs:38:12
| |
LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) { LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
| --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>` | --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/object-lifetime-default-from-box-error.rs:18:5 --> $DIR/object-lifetime-default-from-box-error.rs:22:5
| |
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> { LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
| -- has type `&mut SomeStruct<'1>` | -- has type `&mut SomeStruct<'1>`
@ -13,13 +13,13 @@ LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
| ++++ | ++++
error[E0507]: cannot move out of `ss.r` which is behind a mutable reference error[E0507]: cannot move out of `ss.r` which is behind a mutable reference
--> $DIR/object-lifetime-default-from-box-error.rs:18:5 --> $DIR/object-lifetime-default-from-box-error.rs:22:5
| |
LL | ss.r LL | ss.r
| ^^^^ move occurs because `ss.r` has type `Box<dyn SomeTrait>`, which does not implement the `Copy` trait | ^^^^ move occurs because `ss.r` has type `Box<dyn SomeTrait>`, which does not implement the `Copy` trait
error[E0621]: explicit lifetime required in the type of `ss` error[E0621]: explicit lifetime required in the type of `ss`
--> $DIR/object-lifetime-default-from-box-error.rs:31:5 --> $DIR/object-lifetime-default-from-box-error.rs:38:5
| |
LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) { LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
| --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>` | --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`

View file

@ -1,3 +1,7 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
// Test various cases where the defaults should lead to errors being // Test various cases where the defaults should lead to errors being
// reported. // reported.
@ -15,7 +19,10 @@ fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
// `Box<SomeTrait>` defaults to a `'static` bound, so this return // `Box<SomeTrait>` defaults to a `'static` bound, so this return
// is illegal. // is illegal.
ss.r //~ ERROR E0759 ss.r
//[base]~^ ERROR E0759
//[nll]~^^ ERROR lifetime may not live long enough
//[nll]~| ERROR cannot move out of
} }
fn store(ss: &mut SomeStruct, b: Box<dyn SomeTrait>) { fn store(ss: &mut SomeStruct, b: Box<dyn SomeTrait>) {

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:15:12 --> $DIR/object-lifetime-default-from-rptr-box-error.rs:19:12
| |
LL | ss.t = t; LL | ss.t = t;
| ^ lifetime mismatch | ^ lifetime mismatch
@ -7,7 +7,7 @@ LL | ss.t = t;
= note: expected reference `&'a Box<(dyn Test + 'static)>` = note: expected reference `&'a Box<(dyn Test + 'static)>`
found reference `&'a Box<(dyn Test + 'a)>` found reference `&'a Box<(dyn Test + 'a)>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:14:6 --> $DIR/object-lifetime-default-from-rptr-box-error.rs:18:6
| |
LL | fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) { LL | fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) {
| ^^ | ^^

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:15:5 --> $DIR/object-lifetime-default-from-rptr-box-error.rs:19:5
| |
LL | fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) { LL | fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) {
| -- lifetime `'a` defined here | -- lifetime `'a` defined here

View file

@ -1,3 +1,7 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
// Test that the lifetime from the enclosing `&` is "inherited" // Test that the lifetime from the enclosing `&` is "inherited"
// through the `Box` struct. // through the `Box` struct.
@ -12,7 +16,9 @@ struct SomeStruct<'a> {
} }
fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) { fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) {
ss.t = t; //~ ERROR mismatched types ss.t = t;
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn main() { fn main() {

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:20:12 --> $DIR/object-lifetime-default-from-rptr-struct-error.rs:24:12
| |
LL | ss.t = t; LL | ss.t = t;
| ^ lifetime mismatch | ^ lifetime mismatch
@ -7,7 +7,7 @@ LL | ss.t = t;
= note: expected reference `&'a MyBox<(dyn Test + 'static)>` = note: expected reference `&'a MyBox<(dyn Test + 'static)>`
found reference `&'a MyBox<(dyn Test + 'a)>` found reference `&'a MyBox<(dyn Test + 'a)>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:19:6 --> $DIR/object-lifetime-default-from-rptr-struct-error.rs:23:6
| |
LL | fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) { LL | fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
| ^^ | ^^

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:20:5 --> $DIR/object-lifetime-default-from-rptr-struct-error.rs:24:5
| |
LL | fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) { LL | fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
| -- lifetime `'a` defined here | -- lifetime `'a` defined here

View file

@ -1,3 +1,7 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
// Test that the lifetime from the enclosing `&` is "inherited" // Test that the lifetime from the enclosing `&` is "inherited"
// through the `MyBox` struct. // through the `MyBox` struct.
@ -17,7 +21,9 @@ struct MyBox<T:?Sized> {
} }
fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) { fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
ss.t = t; //~ ERROR mismatched types ss.t = t;
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn main() { fn main() {

View file

@ -1,5 +1,5 @@
error[E0623]: lifetime mismatch error[E0623]: lifetime mismatch
--> $DIR/object-lifetime-default-mybox.rs:27:5 --> $DIR/object-lifetime-default-mybox.rs:31:5
| |
LL | fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>, LL | fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
| ------------------------ this parameter and the return type are declared with different lifetimes... | ------------------------ this parameter and the return type are declared with different lifetimes...
@ -11,7 +11,7 @@ LL | a
| ^ ...but data from `a` is returned here | ^ ...but data from `a` is returned here
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/object-lifetime-default-mybox.rs:31:11 --> $DIR/object-lifetime-default-mybox.rs:37:11
| |
LL | load0(ss) LL | load0(ss)
| ^^ lifetime mismatch | ^^ lifetime mismatch
@ -19,7 +19,7 @@ LL | load0(ss)
= note: expected reference `&MyBox<(dyn SomeTrait + 'static)>` = note: expected reference `&MyBox<(dyn SomeTrait + 'static)>`
found reference `&MyBox<(dyn SomeTrait + 'a)>` found reference `&MyBox<(dyn SomeTrait + 'a)>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/object-lifetime-default-mybox.rs:30:10 --> $DIR/object-lifetime-default-mybox.rs:36:10
| |
LL | fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> { LL | fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
| ^^ | ^^

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough error: lifetime may not live long enough
--> $DIR/object-lifetime-default-mybox.rs:27:5 --> $DIR/object-lifetime-default-mybox.rs:31:5
| |
LL | fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>, LL | fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
| -- -- lifetime `'b` defined here | -- -- lifetime `'b` defined here
@ -12,7 +12,7 @@ LL | a
= help: consider adding the following bound: `'a: 'b` = help: consider adding the following bound: `'a: 'b`
error[E0521]: borrowed data escapes outside of function error[E0521]: borrowed data escapes outside of function
--> $DIR/object-lifetime-default-mybox.rs:31:5 --> $DIR/object-lifetime-default-mybox.rs:37:5
| |
LL | fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> { LL | fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
| -- -- `ss` is a reference that is only valid in the function body | -- -- `ss` is a reference that is only valid in the function body

View file

@ -1,3 +1,7 @@
// ignore-compare-mode-nll
// revisions: base nll
// [nll]compile-flags: -Zborrowck=mir
// Test a "pass-through" object-lifetime-default that produces errors. // Test a "pass-through" object-lifetime-default that produces errors.
#![allow(dead_code)] #![allow(dead_code)]
@ -24,11 +28,15 @@ fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
b: &'b MyBox<dyn SomeTrait>) b: &'b MyBox<dyn SomeTrait>)
-> &'b MyBox<dyn SomeTrait> -> &'b MyBox<dyn SomeTrait>
{ {
a //~ ERROR lifetime mismatch a
//[base]~^ ERROR lifetime mismatch
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> { fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
load0(ss) //~ ERROR mismatched types load0(ss)
//[base]~^ ERROR mismatched types
//[nll]~^^ ERROR borrowed data escapes outside of function
} }
fn main() { fn main() {