-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[nll] better error message when returning refs to upvars #54802
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR achieves (approximately) the intended error from the issue for that test case but I'm not convinced it improves all of the other tests that it is affecting.
| || | ||
| |return type of closure is [closure@$DIR/issue-40510-3.rs:18:9: 20:10 x:&'2 mut std::vec::Vec<()>] | ||
| lifetime `'1` represents this closure's body | ||
| - inferred to be a `FnMut` closure | ||
LL | / || { | ||
LL | | x.push(()) | ||
LL | | } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I suspect this will be a bit confusing because two closures are in play. We actually can probably tell that — if the statement is an assignment with a closure rvalue, then there is an "inner" and an "outer" closure, and maybe we can adjust the message to say something like:
creates a closure that captures
x
by reference; this inner closure is then returned from the outer closure, allowingx
to escape the closure body
that wording doesn't feel 💯, though, and I don't know if it's easy to find the name x
(we don't seem to be using it in other messages)
Maybe something like this?
creates a closure that contains a reference to a captured variable; this inner closure then escapes the closure body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a change with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that @nikomatsakis was suggesting in particular the phrases "inner closure" and "outer closure", in that there are two closures in play and he wanted some way that the diagnostic would distinguish between the two when discussing them.
I don't see any use of the word "inner" in the diff, so I don't think you quite encoded exactly what @nikomatsakis was asking for.
(But I also do think that what you've done is a vast improvement over what we had before...)
/// Adds a suggestion to errors where a `impl Trait` is returned. | ||
/// | ||
/// ```text | ||
/// help: to allow this impl Trait to capture borrowed data with lifetime `'1`, add `'_` as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self: are we literally saying '_
when we mean it as a placeholder for a concrete lifetime like 'a
? Or is it just supposed to be a replacement for the default of 'static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self and to @davidtwco : Wait, so now I don't get a "Submit review" prompt? what the hey...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment annotates a function that was added in a previous PR - I just added it in this PR because I noticed it was missing.
IIRC from that PR, we suggest a named lifetime if we have one and '_
otherwise.
@bors r+ |
📌 Commit b5ba1a0acb74c235cbe06a70ef6c5c1c2e2c0dda has been approved by |
This comment has been minimized.
This comment has been minimized.
This commit improves the errors for `FnMut` closures where a reference to a captured variable is escaping.
Now when a `FnMut` closure is returning a closure that contains a reference to a captured variable, we provide an error that makes it more clear what is happening.
@bors r=pnkfelix |
📌 Commit 98633b4 has been approved by |
⌛ Testing commit 98633b4 with merge 9930347c09c1daa97593944478864af1ebca033d... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors retry |
[nll] better error message when returning refs to upvars Fixes #53040. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Fixes #53040.
r? @nikomatsakis