-
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)NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalT-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.
Milestone
Description
Carrying over a comment from #54088:
I feel like the temporary rules are a common source of confusion. I think we should consider using a distinct error code for them, so that --explain can have some extra text to introduce the rules. Maybe good for a follow-up to this PR though.
As a specific example, consider this test:
rust/src/test/ui/nll/borrowed-temporary-error.rs
Lines 18 to 22 in 7ee7207
let x = gimme({ | |
let v = 22; | |
&(v,) | |
//~^ ERROR borrowed value does not live long enough [E0597] | |
}); |
we give this error:
rust/src/test/ui/nll/borrowed-temporary-error.stderr
Lines 1 to 10 in 7ee7207
error[E0597]: borrowed value does not live long enough | |
--> $DIR/borrowed-temporary-error.rs:20:10 | |
| | |
LL | &(v,) | |
| ^^^^ temporary value does not live long enough | |
LL | //~^ ERROR borrowed value does not live long enough [E0597] | |
LL | }); | |
| - temporary value only lives until here | |
LL | println!("{:?}", x); | |
| - borrow later used here |
but I think we should say something more like this:
error[E9999]: temporary value borrowed for too long
--> $DIR/borrowed-temporary-error.rs:20:10
|
LL | &(v,)
| ^^^^ creates a temporary which is freed while still in use
LL | //~^ ERROR borrowed value does not live long enough [E0597]
LL | });
| - temporary value is freed at the end of this statement
LL | println!("{:?}", x);
| - but the borrow is later used here
Moreover, the extended error for E9999
ought to explain the temporary rules.
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalT-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.