[nll] better error message when returning refs to upvars by davidtwco · Pull Request #54802 · rust-lang/rust (original) (raw)
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