-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
mut
keyword alone unexpectedly dereferences value in pattern matching
#105647
Comments
I don't think this is a bug. |
Are the match ergonomic rules listed somewhere I can learn more about? When they do or don't apply, as you say, isn't very intuitive to me, if it's explained somewhere I would like to learn more about it :) |
The Match Ergonomics RFC is a very good read on this. If you're in a hurry, you can start reading from here. |
I also notice that this issue was last mentioned by @varkor at #64586 (comment). If I understand the match ergonomics RFC correctly, the code above currently gets desugared to: let &[ref a] = &[()];
let &[mut b] = &[()]; // The default binding mode `ref` gets overridden by `mut`.
b = a; which is quite a bit unintuitive. The desugared code I'd expect should be like this: let &[ref a] = &[()];
let mut b = match &[()] {
&[ref b] => b,
};
b = a; I believe that both this issue and #64586 can be and ought to be fixed by a future RFC, in which we should probably consider another approach other than the current one where the default binding mode can be unexpectedly overridden. |
Experiment: lint resetting `mut` bindings We would like to fix rust-lang#105647 in rust 2024. To evaluate the breakage, I wrote a lint that detects the cases where there would be a difference between now and rust 2024. I'd like to request a crater run with `dereferencing_mut_binding` set to `deny` to see how many crates would be affected.
Hi! I was hoping to get this fixed on the new edition. I initially had a complex proposal but turns out the issue is pretty straightforward:
Moreover, the lang team has expressed general agreement to solve this for 2024 (contingent on details being ironed out). But, I'm finding no bandwidth to work on this. So, if anyone wants to take over this, please do. I'm happy to answer questions if you're not entirely clueless about what this would involve (mostly patience to go through the processes, which I don't have enough of). And if not, well we can take our time and get it for 2027. |
I tried this code:
I expected to see this happen: the mutable binding
b
has type&()
, and thus the compilation succeeds without any error.Instead, this happened: the mutable binding
b
has type()
, and the compilation fails with error:Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: