-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Surprising, possibly buggy behavior on &mut patterns in for loops #12250
Comments
Nominating, this could break existing code if we decide to change it. |
The pattern for let foo = &mut ...;
let mut x = *foo;
x = 1.0; i.e. it's not assigning to the reference, just assigning to the new variable with a value that's been copied out of |
I'm not sure what we could change here. Sure, the behaviour is slightly surprising, but it's just a consequence of how patterns and binding work. I'm not convinced that this is anything other than an unexpected consequence and I don't think it's worth making any significant changes. (Since, in reality, the issue is actually the semantics of The only change that makes sense, to me, is making |
Or make |
cc #11144 for parens. |
How about
|
cc me (@huonw's summary is precisely right -- and I think there is |
Closing, not a bug, just a slight footgun. |
… r=Veykril fix: special case base url of `BuiltinType` to core fix rust-lang#12250
Add lint `manual_inspect` fixes rust-lang#12250 A great example of a lint that sounds super simple, but has a pile of edge cases. ---- changelog: Add lint `manual_inspect`
Here's the surprising program:
Compiling produces the following output, which is a head-scratcher if you don't know what's going on:
Running it prints the following:
So even though the error messages are trying to warn you that you're not actually mutating the array, it doesn't answer the question as to why you're not mutating the array.
Intuitively, I expected this program to be equivalent to this:
Which mutates the array as expected.
There's clearly some sort of implicit copying going on here that's very surprising, even if correct. @alexcrichton was also concerned that this might erroneously parsing
&mut pixel
as&(mut pixel)
.So the question is, what behavior do we expect here?
The text was updated successfully, but these errors were encountered: