-
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
Mutable let-else binding produces dereferenced type when deconstructing references #112545
Comments
Your first snippet fails for me with a type mismatch, and if I change the last line to read As for the second snippet, it causes the same error with an if let: pub fn main() {
let value: Option<String> = Some(String::from("Hello"));
let other: String = String::from("World");
/*let Some(mut value) = &value else {
panic!();
};
value = other;*/
if let Some(mut value) = &value {
value = other;
} else {
panic!();
}
}
|
This is a known bug with match ergonomics. I was pushing for it to get fixed for Rust 2021, but unfortunately it never got fixed. |
I was looking for something related to match ergonomics (didn't remember the name), but struggled to find it. Do you have a tracking issue for this bug? |
It's been discussed here: #64586 (comment) Also this RFC intends to somewhat address it too by making it more explicit: rust-lang/rfcs#3410 (comment) |
This comes up regularly. The lang team will discuss fixing this in the 2024 edition! In the meantime, I'm closing this as a duplicate of #105647 |
I tried this code:
In my mind,
value
should be a mutable binding to&u64
, but the desugaring performed seems to cause the mutable binding in particular to result in attempting to move the de-referenced value.This is apparent when dealing with non-copy types:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: