Closed
Description
use std::kinds::marker::NoCopy;
struct FooNonCopyableNoCopy {
a: uint,
b: uint,
nocopy: NoCopy
}
impl Clone for FooNonCopyableNoCopy {
fn clone(&self) -> FooNonCopyableNoCopy {
FooNonCopyableNoCopy { a: self.a + 1, b: self.b + 1, nocopy: NoCopy }
}
}
impl FooNonCopyableNoCopy {
fn new(a: uint, b: uint) -> FooNonCopyableNoCopy {
FooNonCopyableNoCopy { a: a, b: b, nocopy: NoCopy }
}
}
fn consume(mut a: FooNonCopyableNoCopy) {
a.a = a.a + 1;
}
fn bar(a: uint) {
}
fn main() {
let mut a: FooNonCopyableNoCopy = FooNonCopyableNoCopy::new(10, 11);
consume(a);
a.a = 3;
bar(a.a);
}
If you remove bar(a.a)
it will compile. The machine code produced for the X86_64 target is actually passing a reference to consume
which modifies it through the pointer, and then a.a = 3
modifies the same stack instance (stack instance on main stack) but bar(a.a)
errors on usage of moved value.
I think it should disallow the assignment of a.a = 3
because of a
being moved.
Metadata
Metadata
Assignees
Labels
No labels