Skip to content

No error setting fields after a non-Copy struct has moved #21844

@SSheldon

Description

@SSheldon

Noticed in this reddit thread: http://www.reddit.com/r/rust/comments/2ufy4w/how_does_a_shared_ownership_of_a_mutable_source/

The following compiles without issue:

#![feature(collections)]

struct Foo {
    name: String,
}

fn main() {
    let mut x = Foo { name: "Foo".to_string() };
    drop(x);
    x.name = "Bar".to_string();
}

even though we're setting a field on a non-copy struct after it has been dropped. If you try to print out x.name, the compiler correctly errors and says that x has been moved, but it doesn't stop you from setting the field.

Tested on rustc 1.0.0-nightly (1d00c545e 2015-01-30 19:56:34 +0000).

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