Skip to content

Commit 99daba2

Browse files
committed
Use revisions for NLL in object-lifetime
1 parent 8220be5 commit 99daba2

15 files changed

+67
-35
lines changed

src/test/ui/object-lifetime/object-lifetime-default-elision.stderr renamed to src/test/ui/object-lifetime/object-lifetime-default-elision.base.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
error[E0495]: cannot infer an appropriate lifetime for automatic coercion due to conflicting requirements
2-
--> $DIR/object-lifetime-default-elision.rs:71:5
2+
--> $DIR/object-lifetime-default-elision.rs:75:5
33
|
44
LL | ss
55
| ^^
66
|
77
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
8-
--> $DIR/object-lifetime-default-elision.rs:54:10
8+
--> $DIR/object-lifetime-default-elision.rs:58:10
99
|
1010
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
1111
| ^^
1212
note: ...so that reference does not outlive borrowed content
13-
--> $DIR/object-lifetime-default-elision.rs:71:5
13+
--> $DIR/object-lifetime-default-elision.rs:75:5
1414
|
1515
LL | ss
1616
| ^^
1717
note: but, the lifetime must be valid for the lifetime `'b` as defined here...
18-
--> $DIR/object-lifetime-default-elision.rs:54:13
18+
--> $DIR/object-lifetime-default-elision.rs:58:13
1919
|
2020
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
2121
| ^^
2222
note: ...so that the types are compatible
23-
--> $DIR/object-lifetime-default-elision.rs:71:5
23+
--> $DIR/object-lifetime-default-elision.rs:75:5
2424
|
2525
LL | ss
2626
| ^^
2727
= note: expected `&'b (dyn SomeTrait + 'b)`
2828
found `&dyn SomeTrait`
2929

3030
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
31-
--> $DIR/object-lifetime-default-elision.rs:71:5
31+
--> $DIR/object-lifetime-default-elision.rs:75:5
3232
|
3333
LL | ss
3434
| ^^
3535
|
3636
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
37-
--> $DIR/object-lifetime-default-elision.rs:54:10
37+
--> $DIR/object-lifetime-default-elision.rs:58:10
3838
|
3939
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
4040
| ^^
4141
note: ...so that the declared lifetime parameter bounds are satisfied
42-
--> $DIR/object-lifetime-default-elision.rs:71:5
42+
--> $DIR/object-lifetime-default-elision.rs:75:5
4343
|
4444
LL | ss
4545
| ^^
4646
note: but, the lifetime must be valid for the lifetime `'b` as defined here...
47-
--> $DIR/object-lifetime-default-elision.rs:54:13
47+
--> $DIR/object-lifetime-default-elision.rs:58:13
4848
|
4949
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
5050
| ^^
5151
note: ...so that the types are compatible
52-
--> $DIR/object-lifetime-default-elision.rs:71:5
52+
--> $DIR/object-lifetime-default-elision.rs:75:5
5353
|
5454
LL | ss
5555
| ^^

src/test/ui/object-lifetime/object-lifetime-default-elision.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/object-lifetime-default-elision.rs:71:5
2+
--> $DIR/object-lifetime-default-elision.rs:75:5
33
|
44
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
55
| -- -- lifetime `'b` defined here

src/test/ui/object-lifetime/object-lifetime-default-elision.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Test various cases where the old rules under lifetime elision
26
// yield slightly different results than the new rules.
37

@@ -69,8 +73,9 @@ fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
6973
// which fails to type check.
7074

7175
ss
72-
//~^ ERROR cannot infer
73-
//~| ERROR cannot infer
76+
//[base]~^ ERROR cannot infer
77+
//[base]~| ERROR cannot infer
78+
//[nll]~^^^ ERROR lifetime may not live long enough
7479
}
7580

7681
fn main() {

src/test/ui/object-lifetime/object-lifetime-default-from-box-error.stderr renamed to src/test/ui/object-lifetime/object-lifetime-default-from-box-error.base.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0759]: `ss` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
2-
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
2+
--> $DIR/object-lifetime-default-from-box-error.rs:22:5
33
|
44
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
55
| --------------- this data with an anonymous lifetime `'_`...
@@ -8,7 +8,7 @@ LL | ss.r
88
| ^^^^ ...is used and required to live as long as `'static` here
99
|
1010
note: `'static` lifetime requirement introduced by the return type
11-
--> $DIR/object-lifetime-default-from-box-error.rs:14:37
11+
--> $DIR/object-lifetime-default-from-box-error.rs:18:37
1212
|
1313
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
1414
| ^^^^^^^^^^^^^ `'static` requirement introduced here
@@ -21,7 +21,7 @@ LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
2121
| ++++
2222

2323
error[E0621]: explicit lifetime required in the type of `ss`
24-
--> $DIR/object-lifetime-default-from-box-error.rs:31:12
24+
--> $DIR/object-lifetime-default-from-box-error.rs:38:12
2525
|
2626
LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
2727
| --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`

src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
2+
--> $DIR/object-lifetime-default-from-box-error.rs:22:5
33
|
44
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
55
| -- has type `&mut SomeStruct<'1>`
@@ -13,13 +13,13 @@ LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
1313
| ++++
1414

1515
error[E0507]: cannot move out of `ss.r` which is behind a mutable reference
16-
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
16+
--> $DIR/object-lifetime-default-from-box-error.rs:22:5
1717
|
1818
LL | ss.r
1919
| ^^^^ move occurs because `ss.r` has type `Box<dyn SomeTrait>`, which does not implement the `Copy` trait
2020

2121
error[E0621]: explicit lifetime required in the type of `ss`
22-
--> $DIR/object-lifetime-default-from-box-error.rs:31:5
22+
--> $DIR/object-lifetime-default-from-box-error.rs:38:5
2323
|
2424
LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
2525
| --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`

src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Test various cases where the defaults should lead to errors being
26
// reported.
37

@@ -15,7 +19,10 @@ fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
1519
// `Box<SomeTrait>` defaults to a `'static` bound, so this return
1620
// is illegal.
1721

18-
ss.r //~ ERROR E0759
22+
ss.r
23+
//[base]~^ ERROR E0759
24+
//[nll]~^^ ERROR lifetime may not live long enough
25+
//[nll]~| ERROR cannot move out of
1926
}
2027

2128
fn store(ss: &mut SomeStruct, b: Box<dyn SomeTrait>) {

src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr renamed to src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.base.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0308]: mismatched types
2-
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:15:12
2+
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:19:12
33
|
44
LL | ss.t = t;
55
| ^ lifetime mismatch
66
|
77
= note: expected reference `&'a Box<(dyn Test + 'static)>`
88
found reference `&'a Box<(dyn Test + 'a)>`
99
note: the lifetime `'a` as defined here...
10-
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:14:6
10+
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:18:6
1111
|
1212
LL | fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) {
1313
| ^^

src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:15:5
2+
--> $DIR/object-lifetime-default-from-rptr-box-error.rs:19:5
33
|
44
LL | fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) {
55
| -- lifetime `'a` defined here

src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Test that the lifetime from the enclosing `&` is "inherited"
26
// through the `Box` struct.
37

@@ -12,7 +16,9 @@ struct SomeStruct<'a> {
1216
}
1317

1418
fn c<'a>(t: &'a Box<dyn Test+'a>, mut ss: SomeStruct<'a>) {
15-
ss.t = t; //~ ERROR mismatched types
19+
ss.t = t;
20+
//[base]~^ ERROR mismatched types
21+
//[nll]~^^ ERROR lifetime may not live long enough
1622
}
1723

1824
fn main() {

src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr renamed to src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.base.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0308]: mismatched types
2-
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:20:12
2+
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:24:12
33
|
44
LL | ss.t = t;
55
| ^ lifetime mismatch
66
|
77
= note: expected reference `&'a MyBox<(dyn Test + 'static)>`
88
found reference `&'a MyBox<(dyn Test + 'a)>`
99
note: the lifetime `'a` as defined here...
10-
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:19:6
10+
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:23:6
1111
|
1212
LL | fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
1313
| ^^

src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:20:5
2+
--> $DIR/object-lifetime-default-from-rptr-struct-error.rs:24:5
33
|
44
LL | fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
55
| -- lifetime `'a` defined here

src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Test that the lifetime from the enclosing `&` is "inherited"
26
// through the `MyBox` struct.
37

@@ -17,7 +21,9 @@ struct MyBox<T:?Sized> {
1721
}
1822

1923
fn c<'a>(t: &'a MyBox<dyn Test+'a>, mut ss: SomeStruct<'a>) {
20-
ss.t = t; //~ ERROR mismatched types
24+
ss.t = t;
25+
//[base]~^ ERROR mismatched types
26+
//[nll]~^^ ERROR lifetime may not live long enough
2127
}
2228

2329
fn main() {

src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr renamed to src/test/ui/object-lifetime/object-lifetime-default-mybox.base.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0623]: lifetime mismatch
2-
--> $DIR/object-lifetime-default-mybox.rs:27:5
2+
--> $DIR/object-lifetime-default-mybox.rs:31:5
33
|
44
LL | fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
55
| ------------------------ this parameter and the return type are declared with different lifetimes...
@@ -11,15 +11,15 @@ LL | a
1111
| ^ ...but data from `a` is returned here
1212

1313
error[E0308]: mismatched types
14-
--> $DIR/object-lifetime-default-mybox.rs:31:11
14+
--> $DIR/object-lifetime-default-mybox.rs:37:11
1515
|
1616
LL | load0(ss)
1717
| ^^ lifetime mismatch
1818
|
1919
= note: expected reference `&MyBox<(dyn SomeTrait + 'static)>`
2020
found reference `&MyBox<(dyn SomeTrait + 'a)>`
2121
note: the lifetime `'a` as defined here...
22-
--> $DIR/object-lifetime-default-mybox.rs:30:10
22+
--> $DIR/object-lifetime-default-mybox.rs:36:10
2323
|
2424
LL | fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
2525
| ^^

src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/object-lifetime-default-mybox.rs:27:5
2+
--> $DIR/object-lifetime-default-mybox.rs:31:5
33
|
44
LL | fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
55
| -- -- lifetime `'b` defined here
@@ -12,7 +12,7 @@ LL | a
1212
= help: consider adding the following bound: `'a: 'b`
1313

1414
error[E0521]: borrowed data escapes outside of function
15-
--> $DIR/object-lifetime-default-mybox.rs:31:5
15+
--> $DIR/object-lifetime-default-mybox.rs:37:5
1616
|
1717
LL | fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
1818
| -- -- `ss` is a reference that is only valid in the function body

src/test/ui/object-lifetime/object-lifetime-default-mybox.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Test a "pass-through" object-lifetime-default that produces errors.
26

37
#![allow(dead_code)]
@@ -24,11 +28,15 @@ fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
2428
b: &'b MyBox<dyn SomeTrait>)
2529
-> &'b MyBox<dyn SomeTrait>
2630
{
27-
a //~ ERROR lifetime mismatch
31+
a
32+
//[base]~^ ERROR lifetime mismatch
33+
//[nll]~^^ ERROR lifetime may not live long enough
2834
}
2935

3036
fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
31-
load0(ss) //~ ERROR mismatched types
37+
load0(ss)
38+
//[base]~^ ERROR mismatched types
39+
//[nll]~^^ ERROR borrowed data escapes outside of function
3240
}
3341

3442
fn main() {

0 commit comments

Comments
 (0)