-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-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.
Description
In an example where the temporary value is dropped at the end of the statement, such as when the &
is an argument to a fn call, the resulting error can be somewhat misleading:
error: borrowed value does not live long enough
--> <anon>:21:22
|
21 | let r = map.get(&'a');
| ^^^ - borrowed value only valid until here
| |
| does not live long enough
22 | assert_eq!(r, Some(&string));
23 | }
| - borrowed value must be valid until here
|
In particular, the - borrowed value only valid until here
is intended to be "attached" to the ;
, but it kind of looks like it is attached to the ^^^
.
One simple way to improve this would be to change the text -- temporaries are freed at one of two kinds of places:
- innermost enclosing statement (usually);
- note though that the tail expr of a block is contained in the stmt that contains the block (transitively)
- end of block (if syntactically evident that they are assigned into a let binding)
I imagine we could detect which of these two categories we fall into and say "only valid until end of this statement" in the first case or "end of this block" in the second. That might help, though I guess people might not know what a "statement" is.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-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.