Skip to content

Commit e6f68a9

Browse files
authored
Rollup merge of rust-lang#62520 - pnkfelix:add-test-for-42574, r=alexcrichton
Regression test for issue 42574. Cc rust-lang#42574. I'm not going to say this *closes* that issue yet, for two reasons: 1. I am still confused about some aspects of the behavior we are observing that bug 2. The "fix" to the diagnostic relies on full NLL (`#![feature(nll)]`); migration mode still has a subpar diagnostic.
2 parents 8e79343 + 4becbf3 commit e6f68a9

2 files changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This test illustrates a case where full NLL (enabled by the feature
2+
// switch below) produces superior diagnostics to the NLL-migrate
3+
// mode.
4+
5+
#![feature(nll)]
6+
7+
fn doit(data: &'static mut ()) {
8+
|| doit(data);
9+
//~^ ERROR lifetime may not live long enough
10+
//~| ERROR `data` does not live long enough
11+
}
12+
13+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/issue-42574-diagnostic-in-nested-closure.rs:8:8
3+
|
4+
LL | || doit(data);
5+
| -- ^^^^^^^^^^ argument requires that `'1` must outlive `'static`
6+
| |
7+
| lifetime `'1` represents this closure's body
8+
|
9+
= note: closure implements `FnMut`, so references to captured variables can't escape the closure
10+
11+
error[E0597]: `data` does not live long enough
12+
--> $DIR/issue-42574-diagnostic-in-nested-closure.rs:8:13
13+
|
14+
LL | || doit(data);
15+
| -- -----^^^^-
16+
| | | |
17+
| | | borrowed value does not live long enough
18+
| | argument requires that `data` is borrowed for `'static`
19+
| value captured here
20+
...
21+
LL | }
22+
| - `data` dropped here while still borrowed
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)