Skip to content

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

Closed
@mark3982

Description

@mark3982
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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions