{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/45704","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/45704/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/45704/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/45704/events","html_url":"https://github.com/rust-lang/rust/issues/45704","id":270470300,"number":45704,"title":"MIR-borrowck: locals (and thread locals) can remain borrowed after the function ends","user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars1.githubusercontent.com/u/1830974?v=4","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"labels":[{"id":171502053,"url":"https://api.github.com/repos/rust-lang/rust/labels/A-borrow-checker","name":"A-borrow-checker","color":"d7e102","default":false},{"id":267612997,"url":"https://api.github.com/repos/rust-lang/rust/labels/I-unsound","name":"I-unsound","color":"e11d21","default":false},{"id":693557751,"url":"https://api.github.com/repos/rust-lang/rust/labels/WG-compiler-nll","name":"WG-compiler-nll","color":"c2e0c6","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-11-01T22:12:52Z","updated_at":"2017-11-13T19:31:53Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"e.g. this does not give a MIR borrowck error:\r\n\r\n```Rust\r\n#![feature(thread_local)]\r\n\r\n#[thread_local]\r\nstatic FOO: u8 = 3;\r\n\r\nfn assert_static(_t: &'static u8) {}\r\nfn main() {\r\n     assert_static(&FOO);\r\n}\r\n```\r\n\r\nThis is a problem because, as #17954 shows, thread locals end when the current thread ends. AST borrowck currently makes it an error when thread locals are borrowed for more than the current function."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/344031275","html_url":"https://github.com/rust-lang/rust/issues/45704#issuecomment-344031275","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/45704","id":344031275,"user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars1.githubusercontent.com/u/1830974?v=4","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"created_at":"2017-11-13T19:31:53Z","updated_at":"2017-11-13T19:31:53Z","author_association":"CONTRIBUTOR","body":"@nikomatsakis \r\n\r\nI think it will allow you to have \"NLL-style\" cycles if your function doesn't have a destructor. aka:\r\n```Rust\r\nuse std::cell::Cell;\r\n\r\n// no destructor\r\nstruct S<'a>(Cell<Option<&'a S<'a>>>);\r\nfn main() {\r\n    #[cfg(break)] let _d = Box::new(0);\r\n    let x = S(Cell::new(None));\r\n    let y = S(Cell::new(None));\r\n    x.0.set(Some(&y));\r\n    y.0.set(Some(&x));\r\n    panic!()\r\n}\r\n```\r\n\r\nThis currently creates a storagedead -> endregion -> storagedead sequence, which causes a \"borrow does not live long enough\" error, while either with NLL, or if we have a \"mass storagedead at function exit\", it should compile. However, with the \"None terminator\", if we add a destructor in scope, the code will start issuing a borrowck error and therefore be inconsistent.\r\n\r\nI think one good way to deal with it consistently, if we want a stable MIR borrowck without NLL, would be to introduce a bit of CFG-based analysis to MIR borrowck: if we find a sequence of storagedead and endregion instructions (possibly connected by gotos across basic blocks) end all regions first and then kill all the storage. "}}
{"actor":{"display_login":"arielb1"}}