-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when temporary value is a fn call argument, highlighting can be misleading #36279
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
brson
added
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Sep 7, 2016
@jonathandturner I'am ready to fix it after merge #37405 |
bors
added a commit
that referenced
this issue
Nov 12, 2016
Improve "Doesn't live long enough" error case with temporary variable issue #36279 part of #35233 r? @jonathandturner
@nikomatsakis - can you confirm this is fixed now? I think there were some improvements that landed recently |
steveklabnik
added
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
and removed
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Mar 9, 2017
Current output: rustc 1.17.0-nightly (cab4bff3d 2017-03-21)
error: borrowed value does not live long enough
--> <anon>:21:26
|
21 | let r = map.get(&'a');
| --- ^ temporary value dropped here while still borrowed
| |
| temporary value created here
22 | assert_eq!(r, Some(&string));
23 | }
| - temporary value needs to live until here
|
= note: consider using a `let` binding to increase its lifetime
error: aborting due to previous error |
This does seem somewhat better. |
Mark-Simulacrum
added
the
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
label
Jul 26, 2017
This code compiles successfully now. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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: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:
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.
The text was updated successfully, but these errors were encountered: