-
Notifications
You must be signed in to change notification settings - Fork 13.4k
trans codegen injects aliasing of l-values via match ident { ident => ... } #23698
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
Not sure if the title should be changed, but this is an aliasing lvalue bug: fn main() {
let mut a = Box::new(1);
match a {
mut b => {
a = Box::new(2);
println!("{:p} {:p}", &mut a, &mut b);
}
}
} playpen yields @dotdash (doener on IRC) pointed out that the by-value pattern is reusing the location of EDIT: Do note the local variables are aliasing, not the boxes contained within. EDIT2: Simplified the test case by removing the unnecessary loop. |
here is a further reduced example, well-suited for e.g. duplication in #[derive(Debug)]
enum E { C, A, B }
// force E to be zeroed when it goes out of scope
impl Drop for E { fn drop(&mut self) { } }
fn main() {
let mut result = E::A;
match result {
mut x => {
result = E::B;
println!("{:p} {:p}", &mut x, &mut result);
}
}
println!("result: {:?}", result);
} playpen yields:
|
Probably have a fix. The reassignment checker had a bug |
…criminant The reassignment checker effectively only checks whether the last assignment in a body affects the discriminant, but it should of course check all the assignments. Fixes rust-lang#23698
The reassignment checker effectively only checks whether the last assignment in a body affects the discriminant, but it should of course check all the assignments. Fixes rust-lang#23698
trans codegen feeds the zeroed discriminant back into match in a loop
Some examples, courtesy of @eddyb and @dotdash
playpen here yields:
Another one, courtesy of @eddyb:
playpen yields:
The text was updated successfully, but these errors were encountered: