Skip to content
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

Incorrect Allowance Of Assignment Of Moved Variable (NoCopy) #19408

Closed
mark3982 opened this issue Nov 30, 2014 · 1 comment
Closed

Incorrect Allowance Of Assignment Of Moved Variable (NoCopy) #19408

mark3982 opened this issue Nov 30, 2014 · 1 comment

Comments

@mark3982
Copy link

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.

@sfackler
Copy link
Member

Looks like a dup of #18571, which will be fixed by #18963.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants