Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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.

lnicola pushed a commit to lnicola/rust that referenced this issue Apr 28, 2025
refactor: Reduce codegen burden for generated syntax
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants