{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/14270","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/14270/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/14270/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/14270/events","html_url":"https://github.com/rust-lang/rust/issues/14270","id":33744120,"number":14270,"title":"Backwards compatibility hazard with `Box` + `&mut` behaviour that cannot be replicated by a pure-library type","user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-nominated","name":"I-nominated","color":"e10c02"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/P-backcompat-lang","name":"P-backcompat-lang","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rust-lang/rust/milestones/22","labels_url":"https://api.github.com/repos/rust-lang/rust/milestones/22/labels","id":924511,"number":22,"title":"1.0 beta","description":"","creator":{"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},"open_issues":23,"closed_issues":18,"state":"open","created_at":"2015-01-06T21:40:55Z","updated_at":"2015-02-10T12:22:27Z","due_on":null,"closed_at":null},"comments":23,"created_at":"2014-05-18T02:45:52Z","updated_at":"2015-02-10T13:34:25Z","closed_at":null,"body":"With `Box` built deeply into the compiler, one can currently write\r\n\r\n```rust\r\nlet mut y = 1;\r\nlet x: Box<&mut int> = box &mut y;\r\n**x = 2;\r\n```\r\n\r\nThat is, one can mutate through a `&mut` stored in the `Box`, even if the `Box` itself is not in a mutable slot. This is (presumably) because the compiler currently understands a lot about `Box`s behaviour, in particular, that it can act like an immutable unaliased pointer (`&uniq`).\r\n\r\nThere's currently no way to get this behaviour for library types, e.g. `Vec<&mut int>` is theoretically identical to `Box` in terms of ownership/aliasability of its contents, but, as it is a library type, the following cannot be made to work:\r\n\r\n```rust\r\nlet mut y = 1;\r\nlet x: Vec<&mut int> = vec![&mut y];\r\n// error: can't mutate a `& &mut int`\r\n**x.get(0) = 2;\r\n// error: can't borrow x as mutable\r\n**x.get_mut(0) = 2;\r\n```\r\n\r\nWe would need an immutable `&uniq` pointer for this behaviour to be possible for general simply-owned types like an in-library `Box`, `Vec`, `HashMap` etc.\r\n\r\nHaving this behaviour for `Box` represents a possible backwards compatibility hazard if we ever decide to move `Box` more into libraries. Specifically, moving `Box` into a library and preserving its current behaviour perfectly would require (at least) adding this new `&uniq` pointer type.\r\n\r\n(Thanks to /u/SteveMcQwark on reddit for prompting this.)\r\n\r\n(Nominating.)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/73699303","html_url":"https://github.com/rust-lang/rust/issues/14270#issuecomment-73699303","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/14270","id":73699303,"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},"created_at":"2015-02-10T13:34:25Z","updated_at":"2015-02-10T13:34:25Z","body":"nominating: someone needs to own this issue for the beta."}}