Skip to content

Commit 2888a98

Browse files
committed
update tests
Summary: - A few tests that used to compile, but which were highly questionable, now fail to compile. These are tests that also fail under NLL -- they have to do with closures that are returning invalid values (e.g., other closures that contain values that would be out of scope if used), but our regionck rules permitted them for some reason. - One test for #55608 now compiles successfully -- looking at it, I can't I see any reason that it should *not* compile. - Some errors messages changed in small ways, in some cases improving quite a bit, but often just "different".
1 parent 925a081 commit 2888a98

16 files changed

+184
-89
lines changed

src/test/ui/borrowck/borrowck-describe-lvalue.ast.stderr

+27-4
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,31 @@ LL | &mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than
219219
LL | };
220220
| - first borrow ends here
221221

222+
error[E0598]: lifetime of `x` is too short to guarantee its contents can be safely reborrowed
223+
--> $DIR/borrowck-describe-lvalue.rs:305:16
224+
|
225+
LL | || { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
226+
| ^^
227+
|
228+
note: `x` would have to be valid for the expression at 304:12...
229+
--> $DIR/borrowck-describe-lvalue.rs:304:12
230+
|
231+
LL | / || {
232+
LL | | || { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
233+
LL | | //[ast]~^ ERROR lifetime of `x` is too short
234+
LL | | let y = &mut x;
235+
... |
236+
LL | | }
237+
LL | | };
238+
| |____________^
239+
note: ...but `x` is only valid for the lifetime as defined on the body at 304:12
240+
--> $DIR/borrowck-describe-lvalue.rs:304:12
241+
|
242+
LL | || {
243+
| ^^
244+
222245
error[E0499]: cannot borrow `**x` as mutable more than once at a time
223-
--> $DIR/borrowck-describe-lvalue.rs:307:25
246+
--> $DIR/borrowck-describe-lvalue.rs:308:25
224247
|
225248
LL | let y = &mut x;
226249
| - first mutable borrow occurs here
@@ -231,7 +254,7 @@ LL | }
231254
| - first borrow ends here
232255

233256
error[E0382]: use of moved value: `x`
234-
--> $DIR/borrowck-describe-lvalue.rs:318:22
257+
--> $DIR/borrowck-describe-lvalue.rs:319:22
235258
|
236259
LL | drop(x);
237260
| - value moved here
@@ -240,7 +263,7 @@ LL | drop(x); //[ast]~ ERROR use of moved value: `x`
240263
|
241264
= note: move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait
242265

243-
error: aborting due to 26 previous errors
266+
error: aborting due to 27 previous errors
244267

245-
Some errors occurred: E0382, E0499, E0502, E0503.
268+
Some errors occurred: E0382, E0499, E0502, E0503, E0598.
246269
For more information about an error, try `rustc --explain E0382`.

src/test/ui/borrowck/borrowck-describe-lvalue.mir.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | *y = 1;
1010
| ------ first borrow later used here
1111

1212
error[E0499]: cannot borrow `x` as mutable more than once at a time
13-
--> $DIR/borrowck-describe-lvalue.rs:307:20
13+
--> $DIR/borrowck-describe-lvalue.rs:308:20
1414
|
1515
LL | let y = &mut x;
1616
| ------ first mutable borrow occurs here
@@ -26,10 +26,10 @@ error: captured variable cannot escape `FnMut` closure body
2626
LL | || {
2727
| - inferred to be a `FnMut` closure
2828
LL | / || { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
29+
LL | | //[ast]~^ ERROR lifetime of `x` is too short
2930
LL | | let y = &mut x;
3031
LL | | &mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
31-
LL | | //[mir]~^ ERROR cannot borrow `x` as mutable more than once at a time
32-
LL | | *y = 1;
32+
... |
3333
LL | | drop(y);
3434
LL | | }
3535
| |_________________^ returns a closure that contains a reference to a captured variable, which then escapes the closure body
@@ -362,7 +362,7 @@ LL | drop(x);
362362
| - mutable borrow later used here
363363

364364
error[E0382]: use of moved value: `x`
365-
--> $DIR/borrowck-describe-lvalue.rs:318:22
365+
--> $DIR/borrowck-describe-lvalue.rs:319:22
366366
|
367367
LL | drop(x);
368368
| - value moved here

src/test/ui/borrowck/borrowck-describe-lvalue.rs

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ fn main() {
303303
let mut x = 0;
304304
|| {
305305
|| { //[mir]~ ERROR captured variable cannot escape `FnMut` closure body
306+
//[ast]~^ ERROR lifetime of `x` is too short
306307
let y = &mut x;
307308
&mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
308309
//[mir]~^ ERROR cannot borrow `x` as mutable more than once at a time
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
// This used to ICE because it creates an `impl Trait` that captures a
22
// hidden empty region.
3+
//
4+
// compile-pass
35

46
#![feature(conservative_impl_trait)]
57

6-
fn server() -> impl FilterBase2 { //~ ERROR [E0700]
7-
segment2(|| { loop { } }).map2(|| "")
8+
fn server() -> impl FilterBase2 {
9+
segment2(|| loop {}).map2(|| "")
810
}
911

1012
trait FilterBase2 {
11-
fn map2<F>(self, _fn: F) -> Map2<F> where Self: Sized { loop { } }
13+
fn map2<F>(self, _fn: F) -> Map2<F>
14+
where
15+
Self: Sized,
16+
{
17+
loop {}
18+
}
1219
}
1320

14-
struct Map2<F> { _func: F }
21+
struct Map2<F> {
22+
_func: F,
23+
}
1524

16-
impl<F> FilterBase2 for Map2<F> { }
25+
impl<F> FilterBase2 for Map2<F> {}
1726

18-
fn segment2<F>(_fn: F) -> Map2<F> where F: Fn() -> Result<(), ()> {
19-
loop { }
27+
fn segment2<F>(_fn: F) -> Map2<F>
28+
where
29+
F: Fn() -> Result<(), ()>,
30+
{
31+
loop {}
2032
}
2133

22-
fn main() { server(); }
34+
fn main() {
35+
server();
36+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
2-
--> $DIR/issue-55608-captures-empty-region.rs:6:16
1+
warning: the feature `conservative_impl_trait` has been stable since 1.26.0 and no longer requires an attribute to enable
2+
--> $DIR/issue-55608-captures-empty-region.rs:6:12
33
|
4-
LL | fn server() -> impl FilterBase2 { //~ ERROR [E0700]
5-
| ^^^^^^^^^^^^^^^^
4+
LL | #![feature(conservative_impl_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: hidden type `Map2<[closure@$DIR/issue-55608-captures-empty-region.rs:7:36: 7:41]>` captures an empty lifetime
7+
= note: #[warn(stable_features)] on by default
88

9-
error: aborting due to previous error
10-
11-
For more information about this error, try `rustc --explain E0700`.

src/test/ui/issues/issue-40510-1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-pass
11+
// (This regression test *used* to pass, but started to fail once
12+
// #55756 was fixed.)
13+
1214
#![allow(unused)]
1315

1416
fn f() {
1517
let mut x: Box<()> = Box::new(());
1618

1719
|| {
18-
&mut x
20+
&mut x //~ ERROR cannot infer
1921
};
2022
}
2123

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
2+
--> $DIR/issue-40510-1.rs:20:9
3+
|
4+
LL | &mut x //~ ERROR cannot infer
5+
| ^^^^^^
6+
|
7+
note: first, the lifetime cannot outlive the lifetime as defined on the body at 19:5...
8+
--> $DIR/issue-40510-1.rs:19:5
9+
|
10+
LL | || {
11+
| ^^
12+
note: ...so that closure can access `x`
13+
--> $DIR/issue-40510-1.rs:20:9
14+
|
15+
LL | &mut x //~ ERROR cannot infer
16+
| ^^^^^^
17+
note: but, the lifetime must be valid for the expression at 19:5...
18+
--> $DIR/issue-40510-1.rs:19:5
19+
|
20+
LL | / || {
21+
LL | | &mut x //~ ERROR cannot infer
22+
LL | | };
23+
| |_____^
24+
note: ...so type `[closure@$DIR/issue-40510-1.rs:19:5: 21:6 x:&mut std::boxed::Box<()>]` of expression is valid during the expression
25+
--> $DIR/issue-40510-1.rs:19:5
26+
|
27+
LL | / || {
28+
LL | | &mut x //~ ERROR cannot infer
29+
LL | | };
30+
| |_____^
31+
32+
error: aborting due to previous error
33+
34+
For more information about this error, try `rustc --explain E0495`.

src/test/ui/issues/issue-40510-3.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-pass
11+
// (This regression test *used* to pass, but started to fail once
12+
// #55756 was fixed.)
13+
1214
#![allow(unused)]
1315

1416
fn f() {
1517
let mut x: Vec<()> = Vec::new();
1618

1719
|| {
18-
|| {
20+
|| { //~ ERROR too short
1921
x.push(())
2022
}
2123
};
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0598]: lifetime of `x` is too short to guarantee its contents can be safely reborrowed
2+
--> $DIR/issue-40510-3.rs:20:9
3+
|
4+
LL | || { //~ ERROR too short
5+
| ^^
6+
|
7+
note: `x` would have to be valid for the expression at 19:5...
8+
--> $DIR/issue-40510-3.rs:19:5
9+
|
10+
LL | / || {
11+
LL | | || { //~ ERROR too short
12+
LL | | x.push(())
13+
LL | | }
14+
LL | | };
15+
| |_____^
16+
note: ...but `x` is only valid for the lifetime as defined on the body at 19:5
17+
--> $DIR/issue-40510-3.rs:19:5
18+
|
19+
LL | || {
20+
| ^^
21+
22+
error: aborting due to previous error
23+
24+
For more information about this error, try `rustc --explain E0598`.

src/test/ui/issues/issue-49824.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
// This test checks that a failure occurs with NLL but does not fail with the
1414
// legacy AST output. Check issue-49824.nll.stderr for expected compilation error
1515
// output under NLL and #49824 for more information.
16+
//
17+
// UPDATE: Once #55756 was fixed, this test started to fail in both modes.
1618

1719
#[rustc_error]
1820
fn main() {
19-
//~^ compilation successful
2021
let mut x = 0;
2122
|| {
22-
|| {
23+
|| { //~ ERROR too short
2324
let _y = &mut x;
2425
}
2526
};

src/test/ui/issues/issue-49824.stderr

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
error: compilation successful
2-
--> $DIR/issue-49824.rs:18:1
3-
|
4-
LL | / fn main() {
5-
LL | | //~^ compilation successful
6-
LL | | let mut x = 0;
7-
LL | | || {
8-
... |
1+
error[E0598]: lifetime of `x` is too short to guarantee its contents can be safely reborrowed
2+
--> $DIR/issue-49824.rs:23:9
3+
|
4+
LL | || { //~ ERROR too short
5+
| ^^
6+
|
7+
note: `x` would have to be valid for the expression at 22:5...
8+
--> $DIR/issue-49824.rs:22:5
9+
|
10+
LL | / || {
11+
LL | | || { //~ ERROR too short
12+
LL | | let _y = &mut x;
13+
LL | | }
914
LL | | };
10-
LL | | }
11-
| |_^
15+
| |_____^
16+
note: ...but `x` is only valid for the lifetime as defined on the body at 22:5
17+
--> $DIR/issue-49824.rs:22:5
18+
|
19+
LL | || {
20+
| ^^
1221

1322
error: aborting due to previous error
1423

24+
For more information about this error, try `rustc --explain E0598`.

src/test/ui/regions/region-borrow-params-issue-29793-big.ast.stderr

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ LL | WrapB::new().set(|t: bool| if t { x } else { y }) // (separate erro
77
| capture occurs here
88
...
99
LL | });
10-
| - borrowed value dropped before borrower
11-
|
12-
= note: values in a scope are dropped in the opposite order they are created
10+
| - borrowed value only lives until here
11+
...
12+
LL | }
13+
| - borrowed value needs to live until here
1314

1415
error[E0597]: `y` does not live long enough
1516
--> $DIR/region-borrow-params-issue-29793-big.rs:81:54
@@ -20,9 +21,10 @@ LL | WrapB::new().set(|t: bool| if t { x } else { y }) // (separate erro
2021
| capture occurs here
2122
...
2223
LL | });
23-
| - borrowed value dropped before borrower
24-
|
25-
= note: values in a scope are dropped in the opposite order they are created
24+
| - borrowed value only lives until here
25+
...
26+
LL | }
27+
| - borrowed value needs to live until here
2628

2729
error: aborting due to 2 previous errors
2830

src/test/ui/regions/region-borrow-params-issue-29793-small.stderr

+16-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x
77
| capture occurs here
88
...
99
LL | };
10-
| - borrowed value dropped before borrower
11-
|
12-
= note: values in a scope are dropped in the opposite order they are created
10+
| - borrowed value only lives until here
11+
...
12+
LL | }
13+
| - borrowed value needs to live until here
1314

1415
error[E0597]: `y` does not live long enough
1516
--> $DIR/region-borrow-params-issue-29793-small.rs:19:45
@@ -20,9 +21,10 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x
2021
| capture occurs here
2122
...
2223
LL | };
23-
| - borrowed value dropped before borrower
24-
|
25-
= note: values in a scope are dropped in the opposite order they are created
24+
| - borrowed value only lives until here
25+
...
26+
LL | }
27+
| - borrowed value needs to live until here
2628

2729
error[E0597]: `x` does not live long enough
2830
--> $DIR/region-borrow-params-issue-29793-small.rs:34:34
@@ -33,9 +35,10 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x
3335
| capture occurs here
3436
...
3537
LL | };
36-
| - borrowed value dropped before borrower
37-
|
38-
= note: values in a scope are dropped in the opposite order they are created
38+
| - borrowed value only lives until here
39+
...
40+
LL | }
41+
| - borrowed value needs to live until here
3942

4043
error[E0597]: `y` does not live long enough
4144
--> $DIR/region-borrow-params-issue-29793-small.rs:34:45
@@ -46,9 +49,10 @@ LL | let f = |t: bool| if t { x } else { y }; // (separate errors for `x
4649
| capture occurs here
4750
...
4851
LL | };
49-
| - borrowed value dropped before borrower
50-
|
51-
= note: values in a scope are dropped in the opposite order they are created
52+
| - borrowed value only lives until here
53+
...
54+
LL | }
55+
| - borrowed value needs to live until here
5256

5357
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
5458
--> $DIR/region-borrow-params-issue-29793-small.rs:65:17

0 commit comments

Comments
 (0)