-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
return x; and x not equivalent at end of function? #43837
Comments
They are not equivalent. The destructor for |
In that case I think this is a documentation issue. https://doc.rust-lang.org/reference/items.html#functions suggests that they are equivalent:
|
That paragraph is actually sort-of correct - what matters is whether there's a semicolon (making for a return statement) or not (see https://play.rust-lang.org/?gist=763b754c7393eb72d3d8b79721dba3ba&version=stable - a non-semicoloned return expression. OTOH, that reference section is entirely a lie for several reasons. Let's fix it |
But why isn't this applied though? If it happens that the lifetimes of both 'possible' and 'possible.drain()' end at the same point(when function scope ends?), then shouldn't they be Why does EDIT: well, nevermind this, I guess there are more pressing issues like rust-lang/rfcs#811 which may or may not affect this when fixed. EDIT2: thanks to oli_obk for linking me to the old 2015 issue here #21114 (comment) |
the code in OP is now working by prepending the line now, let me just take a moment to praise the NLL gods... 🥇 |
I have some code which the borrow checker doesn't agree with. However, it works fine if I replace the expression at the end of the function with a return statement containing the same expression. I believed that
return x;
was fully equivalent tox
at the end of a function, but apparently not? Not sure if this is a documentation issue or a compiler bug, but after raising this on #rust-beginners it was recommended that I raise it here :)The text was updated successfully, but these errors were encountered: