-
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
Replacing a parameter declared as mut a
with let mut a = a;
causes program to no longer compile
#31723
Comments
This is the destruction order problem: the destructor of |
@arielb1 I was under the impression that destructors ran in reverse order of declaration, so surely the destructor of |
I would need to go review the temp r-value lifetime rules in a case like this, in terms of how the temporaries of the final expression in a block relate to the local variables in that block (I know it's unintuitive for explicit return to work in cases like this that are supposedly equivalent ...) |
@pnkfelix If/when you review those rules, could you perhaps check whether the root cause is the same as the example here? |
Closing in favor of #21114. Please reopen if that's incorrect, but from what I can tell this is a duplicate of that issue. |
This may very well be a dupe of #31439, but it manifests somewhat differently and may shed light on the potential fix. Probably still worth having a test case for anyway.
Take this program, which compiles:
Now, instead of declaring the parameter as
mut a
, declare it as immutable and rebind it as mutable in the body of the function, which is supposed to be semantically equivalent. This results in a compiler error:As in #31439, replacing the implicit return with an explicit return also allows the program to compile.
The text was updated successfully, but these errors were encountered: