-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Wrong code with assignment in match body #26996
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
Comments
Actually what happens here is the following: The tuple you create in The whole thing is confusing because Rust does not warn when you perform useless assignments to moved variables, and it probably should. The whole thing becomes obviously when you add a statement that uses fn main() {
let mut c = (1, "".to_owned());
match c {
c2 => { println!("{}", c.0); c.0 = 2; assert_eq!(c2.0, 1); }
}
} Edit: @Aatch the labels you have assigned to this issue are incorrect. |
Don't we see the new value Doing this without a match statement passes the same assertion sucessfully: fn main() {
let mut c = (1, "".to_owned());
let c2 = c;
c.0 = 2;
assert_eq!(c2.0, 1);
} |
Oops, you are correct, I am mistaken :( On Mon, Jul 13, 2015 at 10:52 AM, mitaa [email protected] wrote:
|
If we match a whole struct or tuple, the "field" for the reassignment checker will be "None" which means that mutating any field should count as a reassignment. Fixes rust-lang#26996.
If we match a whole struct or tuple, the "field" for the reassignment checker will be "None" which means that mutating any field should count as a reassignment. Fixes #26996.
@Thiez heh, I made the same mistake. Typed out most of a response and then realised that I'd mis-read the code. |
The text was updated successfully, but these errors were encountered: