{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/21232","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/21232/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/21232/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/21232/events","html_url":"https://github.com/rust-lang/rust/issues/21232","id":54566513,"number":21232,"title":"borrow-checker allows partial reinit of struct that has been moved away, but no use of it.","user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-typesystem","name":"A-typesystem","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-needs-decision","name":"I-needs-decision","color":"e11d21"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/P-low","name":"P-low","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-01-16T11:39:23Z","updated_at":"2015-03-10T11:25:23Z","closed_at":null,"body":"Here is some sample code:\r\n\r\n```rust\r\n#[derive(Show)]\r\nstruct Pair { lft: u8, rgt: u8, }\r\n\r\nfn main() {\r\n    let mut p = Pair { lft: 1, rgt: 2 };\r\n    let mut f = move |&mut:| { p.lft = 3; p.rgt };\r\n    p.rgt = 4;\r\n    println!(\"f: {:?}\", f());\r\n    p.lft = 5;\r\n    // println!(\"p: {:?}\", p);\r\n}\r\n```\r\n\r\nThis compiles without an error; running it prints `f: 2u8`.\r\n\r\nIf you uncomment the last line, you get an error saying \"error: use of moved value: `p`\".  Likewise if you just attempt to print individual fields.\r\n\r\nWhile I do see the logic being used here (\"we are not overwriting the value within the closure itself; we are writing into the uninitialized memory that resulted from moving `p` into the closure\"), it seems potentially confusing.\r\n\r\nIs there any reason that we allowing these writes, which cannot be subsequently read?  It seems like a situation analogous to moving into a moved-away array (see https://github.com/rust-lang/rfcs/pull/533 )"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/78036007","html_url":"https://github.com/rust-lang/rust/issues/21232#issuecomment-78036007","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/21232","id":78036007,"user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T11:25:23Z","updated_at":"2015-03-10T11:25:23Z","body":"@mbrubeck yes, we are more restrictive about structs with destructors, because in that case it doesn't make sense to drop one part and not another."}}