From 99daba2a4a17c733f4edf781fde6fa8cb30975a0 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sat, 21 May 2022 14:45:57 -0400 Subject: [PATCH] Use revisions for NLL in object-lifetime --- ...ject-lifetime-default-elision.base.stderr} | 20 +++++++++---------- ...object-lifetime-default-elision.nll.stderr | 2 +- .../object-lifetime-default-elision.rs | 9 +++++++-- ...fetime-default-from-box-error.base.stderr} | 6 +++--- ...lifetime-default-from-box-error.nll.stderr | 6 +++--- .../object-lifetime-default-from-box-error.rs | 9 ++++++++- ...e-default-from-rptr-box-error.base.stderr} | 4 ++-- ...ime-default-from-rptr-box-error.nll.stderr | 2 +- ...ct-lifetime-default-from-rptr-box-error.rs | 8 +++++++- ...efault-from-rptr-struct-error.base.stderr} | 4 ++-- ...-default-from-rptr-struct-error.nll.stderr | 2 +- ...lifetime-default-from-rptr-struct-error.rs | 8 +++++++- ...object-lifetime-default-mybox.base.stderr} | 6 +++--- .../object-lifetime-default-mybox.nll.stderr | 4 ++-- .../object-lifetime-default-mybox.rs | 12 +++++++++-- 15 files changed, 67 insertions(+), 35 deletions(-) rename src/test/ui/object-lifetime/{object-lifetime-default-elision.stderr => object-lifetime-default-elision.base.stderr} (75%) rename src/test/ui/object-lifetime/{object-lifetime-default-from-box-error.stderr => object-lifetime-default-from-box-error.base.stderr} (88%) rename src/test/ui/object-lifetime/{object-lifetime-default-from-rptr-box-error.stderr => object-lifetime-default-from-rptr-box-error.base.stderr} (80%) rename src/test/ui/object-lifetime/{object-lifetime-default-from-rptr-struct-error.stderr => object-lifetime-default-from-rptr-struct-error.base.stderr} (80%) rename src/test/ui/object-lifetime/{object-lifetime-default-mybox.stderr => object-lifetime-default-mybox.base.stderr} (87%) diff --git a/src/test/ui/object-lifetime/object-lifetime-default-elision.stderr b/src/test/ui/object-lifetime/object-lifetime-default-elision.base.stderr similarity index 75% rename from src/test/ui/object-lifetime/object-lifetime-default-elision.stderr rename to src/test/ui/object-lifetime/object-lifetime-default-elision.base.stderr index 5af4c5bdfaed..c402d1fefad6 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-elision.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-elision.base.stderr @@ -1,26 +1,26 @@ 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 | ^^ | 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 { | ^^ 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 | ^^ 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 { | ^^ 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 | ^^ @@ -28,28 +28,28 @@ LL | ss found `&dyn SomeTrait` 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 | ^^ | 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 { | ^^ 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 | ^^ 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 { | ^^ 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 | ^^ diff --git a/src/test/ui/object-lifetime/object-lifetime-default-elision.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-elision.nll.stderr index 61e96f59fed9..49bbadf7224b 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-elision.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-elision.nll.stderr @@ -1,5 +1,5 @@ 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 { | -- -- lifetime `'b` defined here diff --git a/src/test/ui/object-lifetime/object-lifetime-default-elision.rs b/src/test/ui/object-lifetime/object-lifetime-default-elision.rs index dc42edfba2cc..16b4df7bad5e 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-elision.rs +++ b/src/test/ui/object-lifetime/object-lifetime-default-elision.rs @@ -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 // 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. ss - //~^ ERROR cannot infer - //~| ERROR cannot infer + //[base]~^ ERROR cannot infer + //[base]~| ERROR cannot infer + //[nll]~^^^ ERROR lifetime may not live long enough } fn main() { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.base.stderr similarity index 88% rename from src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr rename to src/test/ui/object-lifetime/object-lifetime-default-from-box-error.base.stderr index 1708700f77aa..5a8cba175e93 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.base.stderr @@ -1,5 +1,5 @@ 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 { | --------------- this data with an anonymous lifetime `'_`... @@ -8,7 +8,7 @@ LL | ss.r | ^^^^ ...is used and required to live as long as `'static` here | 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 { | ^^^^^^^^^^^^^ `'static` requirement introduced here @@ -21,7 +21,7 @@ LL | fn load(ss: &mut SomeStruct) -> Box { | ++++ 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) { | --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>` diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr index 43695a7511d2..7907813f2674 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr @@ -1,5 +1,5 @@ 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 { | -- has type `&mut SomeStruct<'1>` @@ -13,13 +13,13 @@ LL | fn load(ss: &mut SomeStruct) -> Box { | ++++ 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 | ^^^^ move occurs because `ss.r` has type `Box`, which does not implement the `Copy` trait 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) { | --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>` diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs index 4a2665d8e169..1cb9834913ca 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs @@ -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 // reported. @@ -15,7 +19,10 @@ fn load(ss: &mut SomeStruct) -> Box { // `Box` defaults to a `'static` bound, so this return // 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) { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.base.stderr similarity index 80% rename from src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr rename to src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.base.stderr index e7fab9ecefcd..7e88aa32357d 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.base.stderr @@ -1,5 +1,5 @@ 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; | ^ lifetime mismatch @@ -7,7 +7,7 @@ LL | ss.t = t; = note: expected reference `&'a Box<(dyn Test + 'static)>` found reference `&'a Box<(dyn Test + 'a)>` 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, mut ss: SomeStruct<'a>) { | ^^ diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.nll.stderr index 7d6f9f39d13e..a07cc0718f11 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.nll.stderr @@ -1,5 +1,5 @@ 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, mut ss: SomeStruct<'a>) { | -- lifetime `'a` defined here diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.rs b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.rs index bf9e0beb57cd..8cdd64be193e 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.rs +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.rs @@ -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" // through the `Box` struct. @@ -12,7 +16,9 @@ struct SomeStruct<'a> { } fn c<'a>(t: &'a Box, 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() { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.base.stderr similarity index 80% rename from src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr rename to src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.base.stderr index 1649841c1868..b97a7d225499 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.base.stderr @@ -1,5 +1,5 @@ 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; | ^ lifetime mismatch @@ -7,7 +7,7 @@ LL | ss.t = t; = note: expected reference `&'a MyBox<(dyn Test + 'static)>` found reference `&'a MyBox<(dyn Test + 'a)>` 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, mut ss: SomeStruct<'a>) { | ^^ diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.nll.stderr index 2bc8e097859d..63d51b5c28c6 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.nll.stderr @@ -1,5 +1,5 @@ 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, mut ss: SomeStruct<'a>) { | -- lifetime `'a` defined here diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.rs b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.rs index dc0b86903c9e..2d9a148a389c 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.rs +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.rs @@ -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" // through the `MyBox` struct. @@ -17,7 +21,9 @@ struct MyBox { } fn c<'a>(t: &'a MyBox, 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() { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr b/src/test/ui/object-lifetime/object-lifetime-default-mybox.base.stderr similarity index 87% rename from src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr rename to src/test/ui/object-lifetime/object-lifetime-default-mybox.base.stderr index 4c5fb452ebe4..6a72fab307b6 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-mybox.base.stderr @@ -1,5 +1,5 @@ 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, | ------------------------ this parameter and the return type are declared with different lifetimes... @@ -11,7 +11,7 @@ LL | a | ^ ...but data from `a` is returned here error[E0308]: mismatched types - --> $DIR/object-lifetime-default-mybox.rs:31:11 + --> $DIR/object-lifetime-default-mybox.rs:37:11 | LL | load0(ss) | ^^ lifetime mismatch @@ -19,7 +19,7 @@ LL | load0(ss) = note: expected reference `&MyBox<(dyn SomeTrait + 'static)>` found reference `&MyBox<(dyn SomeTrait + 'a)>` 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) -> MyBox { | ^^ diff --git a/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr index af20c5e5fc0d..aa454cb99315 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr @@ -1,5 +1,5 @@ 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, | -- -- lifetime `'b` defined here @@ -12,7 +12,7 @@ LL | a = help: consider adding the following bound: `'a: 'b` 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) -> MyBox { | -- -- `ss` is a reference that is only valid in the function body diff --git a/src/test/ui/object-lifetime/object-lifetime-default-mybox.rs b/src/test/ui/object-lifetime/object-lifetime-default-mybox.rs index eb27fe90f47c..874556dafebf 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-mybox.rs +++ b/src/test/ui/object-lifetime/object-lifetime-default-mybox.rs @@ -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. #![allow(dead_code)] @@ -24,11 +28,15 @@ fn load1<'a,'b>(a: &'a MyBox, b: &'b MyBox) -> &'b MyBox { - a //~ ERROR lifetime mismatch + a + //[base]~^ ERROR lifetime mismatch + //[nll]~^^ ERROR lifetime may not live long enough } fn load2<'a>(ss: &MyBox) -> MyBox { - load0(ss) //~ ERROR mismatched types + load0(ss) + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR borrowed data escapes outside of function } fn main() {