{"action":"created","issue":{"url":"https://api.github.com/repos/nikomatsakis/rust-memory-model/issues/12","repository_url":"https://api.github.com/repos/nikomatsakis/rust-memory-model","labels_url":"https://api.github.com/repos/nikomatsakis/rust-memory-model/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/nikomatsakis/rust-memory-model/issues/12/comments","events_url":"https://api.github.com/repos/nikomatsakis/rust-memory-model/issues/12/events","html_url":"https://github.com/nikomatsakis/rust-memory-model/issues/12","id":172043419,"number":12,"title":"Is it undefined behavior to hold an invalid reference, if it is never dereferenced.","user":{"login":"mystor","id":1261662,"avatar_url":"https://avatars.githubusercontent.com/u/1261662?v=3","gravatar_id":"","url":"https://api.github.com/users/mystor","html_url":"https://github.com/mystor","followers_url":"https://api.github.com/users/mystor/followers","following_url":"https://api.github.com/users/mystor/following{/other_user}","gists_url":"https://api.github.com/users/mystor/gists{/gist_id}","starred_url":"https://api.github.com/users/mystor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mystor/subscriptions","organizations_url":"https://api.github.com/users/mystor/orgs","repos_url":"https://api.github.com/users/mystor/repos","events_url":"https://api.github.com/users/mystor/events{/privacy}","received_events_url":"https://api.github.com/users/mystor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-08-19T02:44:31Z","updated_at":"2016-08-27T16:28:57Z","closed_at":null,"body":"It is not Safe in rust code to create invalid references, in that these references can be used by safe code to trigger Undefined Behavior, however, is it Undefined Behavior to create one of these references?\r\n\r\nFor example, does this code trigger Undefined Behavior?\r\n```rust\r\nstruct Foo {...}\r\nlet _x: &const Foo = &*(1024 as *const Foo);\r\n```\r\n\r\nHow about this code, which gets the address of the member, but does no reading?\r\n```rust\r\nstruct Foo {\r\n    member: i32\r\n}\r\nlet _x: &i32 = &(*(1024 as *const Foo)).member;\r\n```\r\n\r\nHow about this code, which creates an invalid reference by over-extending the lifetime, but does not follow it?\r\n```rust\r\nstruct Foo {...}\r\nlet _x: &'static Foo;\r\n{\r\n    let y = Foo {...};\r\n    _x = mem::transmute(&y);\r\n}\r\n```\r\n\r\nOr this code, which creates a reference with the wrong lifetime, but only follows it while the object behind it is still alive?\r\n```rust\r\nstruct Foo {\r\n    member: i32\r\n}\r\nlet y: &'static Foo;\r\n{\r\n    let x = Foo {...};\r\n    y = mem::transmute(&x);\r\n    println!(\"y.member = {}\", y.member);\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/nikomatsakis/rust-memory-model/issues/comments/242926803","html_url":"https://github.com/nikomatsakis/rust-memory-model/issues/12#issuecomment-242926803","issue_url":"https://api.github.com/repos/nikomatsakis/rust-memory-model/issues/12","id":242926803,"user":{"login":"eternaleye","id":99404,"avatar_url":"https://avatars.githubusercontent.com/u/99404?v=3","gravatar_id":"","url":"https://api.github.com/users/eternaleye","html_url":"https://github.com/eternaleye","followers_url":"https://api.github.com/users/eternaleye/followers","following_url":"https://api.github.com/users/eternaleye/following{/other_user}","gists_url":"https://api.github.com/users/eternaleye/gists{/gist_id}","starred_url":"https://api.github.com/users/eternaleye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eternaleye/subscriptions","organizations_url":"https://api.github.com/users/eternaleye/orgs","repos_url":"https://api.github.com/users/eternaleye/repos","events_url":"https://api.github.com/users/eternaleye/events{/privacy}","received_events_url":"https://api.github.com/users/eternaleye/received_events","type":"User","site_admin":false},"created_at":"2016-08-27T16:28:57Z","updated_at":"2016-08-27T16:28:57Z","body":"@ubsan: An invalid reference is a reference that doesn't satisfy its contract, just like an invalid instance of any other type.\r\n\r\nFor references, the contract is that it points to a value of the specified type, and that the value outlives the specified lifetime."}}
{"actor":{"display_login":"eternaleye"}}