{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/51110","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/51110/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/51110/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/51110/events","html_url":"https://github.com/rust-lang/rust/pull/51110","id":326828828,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkwNzk0OTQx","number":51110,"title":"Loosened rules involving statics mentioning other statics","user":{"login":"alexreg","id":67036,"node_id":"MDQ6VXNlcjY3MDM2","avatar_url":"https://avatars3.githubusercontent.com/u/67036?v=4","gravatar_id":"","url":"https://api.github.com/users/alexreg","html_url":"https://github.com/alexreg","followers_url":"https://api.github.com/users/alexreg/followers","following_url":"https://api.github.com/users/alexreg/following{/other_user}","gists_url":"https://api.github.com/users/alexreg/gists{/gist_id}","starred_url":"https://api.github.com/users/alexreg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexreg/subscriptions","organizations_url":"https://api.github.com/users/alexreg/orgs","repos_url":"https://api.github.com/users/alexreg/repos","events_url":"https://api.github.com/users/alexreg/events{/privacy}","received_events_url":"https://api.github.com/users/alexreg/received_events","type":"User","site_admin":false},"labels":[{"id":583436937,"node_id":"MDU6TGFiZWw1ODM0MzY5Mzc=","url":"https://api.github.com/repos/rust-lang/rust/labels/S-waiting-on-author","name":"S-waiting-on-author","color":"d3dddd","default":false},{"id":211668019,"node_id":"MDU6TGFiZWwyMTE2NjgwMTk=","url":"https://api.github.com/repos/rust-lang/rust/labels/T-lang","name":"T-lang","color":"bfd4f2","default":false},{"id":919710011,"node_id":"MDU6TGFiZWw5MTk3MTAwMTE=","url":"https://api.github.com/repos/rust-lang/rust/labels/disposition-merge","name":"disposition-merge","color":"008800","default":false},{"id":923282386,"node_id":"MDU6TGFiZWw5MjMyODIzODY=","url":"https://api.github.com/repos/rust-lang/rust/labels/finished-final-comment-period","name":"finished-final-comment-period","color":"f9e189","default":false}],"state":"open","locked":false,"assignee":{"login":"eddyb","id":77424,"node_id":"MDQ6VXNlcjc3NDI0","avatar_url":"https://avatars2.githubusercontent.com/u/77424?v=4","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false},"assignees":[{"login":"eddyb","id":77424,"node_id":"MDQ6VXNlcjc3NDI0","avatar_url":"https://avatars2.githubusercontent.com/u/77424?v=4","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false}],"milestone":null,"comments":53,"created_at":"2018-05-27T16:10:37Z","updated_at":"2018-07-01T19:33:57Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/51110","html_url":"https://github.com/rust-lang/rust/pull/51110","diff_url":"https://github.com/rust-lang/rust/pull/51110.diff","patch_url":"https://github.com/rust-lang/rust/pull/51110.patch"},"body":"Before this PR, trying to mention a static in any way other than taking a reference to it caused a compile-time error. So, while\r\n\r\n```rust\r\nstatic A: u32 = 42;\r\nstatic B: &u32 = &A;\r\n```\r\n\r\ncompiles successfully,\r\n\r\n```rust\r\nstatic A: u32 = 42;\r\nstatic B: u32 = A; // error\r\n```\r\n\r\nand \r\n\r\n```rust\r\nstatic A: u32 = 42;\r\nstatic B: u32 = *&A; // error\r\n```\r\n\r\nare not possible to express in Rust. On the other hand, introducing an intermediate `const fn` can presently allow one to do just that:\r\n\r\n```rust\r\nstatic A: u32 = 42;\r\nstatic B: u32 = foo(&A); // success!\r\n\r\nconst fn foo(a: &u32) -> u32 {\r\n    *a\r\n}\r\n```\r\n\r\nPreventing `const fn` from allowing to work around the ban on reading from statics would cripple `const fn` almost into uselessness.\r\nAdditionally, the limitation for reading from statics comes from the old const evaluator(s) and is not shared by `miri`.\r\n\r\nThis PR loosens the rules around use of statics to allow statics to evaluate other statics by value, allowing all of the above examples to compile and run successfully.\r\nReads from extern (foreign) statics are however still disallowed by miri, because there is no compile-time value to be read.\r\n\r\n```rust\r\nextern static A: u32;\r\n\r\nstatic B: u32 = A; // error\r\n```\r\n\r\nThis opens up a new avenue of potential issues, as a static can now not just refer to other statics or read from other statics, but even contain references that point into itself.\r\nWhile it might seem like this could cause subtle bugs like allowing a static to be initialized by its own value, this is inherently impossible in miri.\r\nReading from a static causes the `const_eval` query for that static to be invoked. Calling the `const_eval` query for a static while already inside the `const_eval` query of said static will cause cycle errors.\r\nIt is not possible to accidentally create a bug in miri that would enable initializing a static with itself, because the memory of the static *does not exist* while being initialized.\r\nThe memory is not uninitialized, it is not there. Thus any change that would accidentally allow reading from a not yet initialized static would cause ICEs.\r\n\r\nTests have been modified according to the new rules, and new tests have been added for writing to `static mut`s within definitions of statics (which needs to fail), and incremental compilation with complex/interlinking static definitions.\r\nNote that incremental compilation did not need to be adjusted, because all of this was already possible before with workarounds (like intermediate `const fn`s) and the encoding/decoding already supports all the possible cases.\r\n\r\nr? @eddyb"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/401627932","html_url":"https://github.com/rust-lang/rust/pull/51110#issuecomment-401627932","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/51110","id":401627932,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMTYyNzkzMg==","user":{"login":"oli-obk","id":332036,"node_id":"MDQ6VXNlcjMzMjAzNg==","avatar_url":"https://avatars2.githubusercontent.com/u/332036?v=4","gravatar_id":"","url":"https://api.github.com/users/oli-obk","html_url":"https://github.com/oli-obk","followers_url":"https://api.github.com/users/oli-obk/followers","following_url":"https://api.github.com/users/oli-obk/following{/other_user}","gists_url":"https://api.github.com/users/oli-obk/gists{/gist_id}","starred_url":"https://api.github.com/users/oli-obk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oli-obk/subscriptions","organizations_url":"https://api.github.com/users/oli-obk/orgs","repos_url":"https://api.github.com/users/oli-obk/repos","events_url":"https://api.github.com/users/oli-obk/events{/privacy}","received_events_url":"https://api.github.com/users/oli-obk/received_events","type":"User","site_admin":false},"created_at":"2018-07-01T19:33:57Z","updated_at":"2018-07-01T19:33:57Z","author_association":"CONTRIBUTOR","body":"@bors r=eddyb"}}
{"actor":{"display_login":"oli-obk"}}