Skip to content

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

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
SSheldon opened this issue Feb 1, 2015 · 1 comment
Closed

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

SSheldon opened this issue Feb 1, 2015 · 1 comment

Comments

@SSheldon
Copy link
Contributor

SSheldon commented Feb 1, 2015

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).

@sfackler
Copy link
Member

sfackler commented Feb 1, 2015

Dup of #18571

# 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