-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalP-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
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
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalP-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.