Closed
Description
For this code:
fn doit(data: &'static mut ()) {
|| doit(data);
}
(works fine if you drop the mut
, still happens with a move
closure).
The compiler (stable and nightly) spits out this error:
error[E0313]: lifetime of borrowed pointer outlives lifetime of captured variable `data`...
--> <anon>:3:13
|
3 | || doit(data);
| ^^^^
|
= note: ...the borrowed pointer is valid for the static lifetime...
note: ...but `data` is only valid for the lifetime as defined on the body at 3:7
--> <anon>:3:8
|
3 | || doit(data);
| ^^^^^^^^^^
error: aborting due to previous error
- The last note is broken:
for the lifetime as defined on
the actual lifetime is invisible. There is also no lifetime defined in the entire program, so it's not clear which lifetime the note is talking about. - The main error message is very unclear. Is it saying that
data
itself must live as long as the data behind the reference? Why?
According to the rustc source code, this error is related to an implicit reborrow done by the closure. The error mentions nothing of that sort.
Metadata
Metadata
Assignees
Labels
Area: Non-lexical lifetimes (NLL)Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsCategory: An issue proposing an enhancement or a PR with one.Working towards the "diagnostic parity" goalLow priorityRelevant to the compiler team, which will review and decide on the PR/issue.Bugs fixed, but only when NLL is enabled.