-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 vector modified in-place while evaluating right side of assignment #16602
Comments
Nominating. This may not be a 1.0 backcompat-lang issue though as it seems fairly rare. |
Same thing with structs: struct A {
pub x: uint,
pub y: uint
}
fn main() {
let mut a = A { x: 1, y: 1 };
a = A { x: a.y * 2, y: a.x * 2 };
assert_eq!(a.x, 2);
assert_eq!(a.y, 2);
} |
OK, same thing happens with enums, which is a bit more serious since it now affects memory safety. #[deriving(Show)]
enum Foo {
Bar(uint, uint),
Baz(&'static uint, &'static uint)
}
static num: uint = 100;
fn main () {
let mut b = Baz(&num, &num);
b = Bar(f(&b), g(&b));
println!("main: {}", b);
}
static fnum: uint = 1;
fn f (b: &Foo) -> uint {
println!("f : {}", b);
fnum
}
static gnum: uint = 2;
fn g (b: &Foo) -> uint {
println!("g : {}", b);
gnum
}
|
I believe this problem is in trans -- it is supposed to used a temporary buffer for these sorts of cases, but obviously that check is not working correctly. |
Team believes this to be a miscompilation issue (and not, as we feared at first, a failure of the borrow-checker to reject an incorrect program). That is, these programs should be compilable; the problem is that the generated code is wrong. P-high, not 1.0. |
All of the code examples from this ticket seem to work now: So I think this just needs regression tests. |
Move some tests to more reasonable places cc rust-lang#73494 r? `@petrochenkov` 16602 -> `codegen` because of rust-lang#16602 (comment)
Assigning to a mutable vector causes it to be modified in-place even if the right side of the assignment references it.
On IRC, @Kimundi pointed me to #15300, which might be related.
The text was updated successfully, but these errors were encountered: