{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/49327","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/49327/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/49327/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/49327/events","html_url":"https://github.com/rust-lang/rust/issues/49327","id":308262764,"number":49327,"title":"Rustc creates invalid mir for core::cell::BorrowRef::new","user":{"login":"bjorn3","id":17426603,"avatar_url":"https://avatars1.githubusercontent.com/u/17426603?v=4","gravatar_id":"","url":"https://api.github.com/users/bjorn3","html_url":"https://github.com/bjorn3","followers_url":"https://api.github.com/users/bjorn3/followers","following_url":"https://api.github.com/users/bjorn3/following{/other_user}","gists_url":"https://api.github.com/users/bjorn3/gists{/gist_id}","starred_url":"https://api.github.com/users/bjorn3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjorn3/subscriptions","organizations_url":"https://api.github.com/users/bjorn3/orgs","repos_url":"https://api.github.com/users/bjorn3/repos","events_url":"https://api.github.com/users/bjorn3/events{/privacy}","received_events_url":"https://api.github.com/users/bjorn3/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-24T13:33:33Z","updated_at":"2018-03-24T13:33:33Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Repro (copy of necessary parts of libcore/cell.rs): https://play.rust-lang.org/?gist=41cc5138c7765666a646bbcb09748ff3&version=stable\r\n\r\nNotice the second statement in bb1: `_4 = discriminant(_2);` _2 is of type `usize` on which you are not allowed to the discriminant. `_4` isn't used anywhere. This has been detected while fixing miri.\r\n\r\ncc @solson @oli-obk\r\n\r\n```rust\r\nfn <impl at src/main.rs:11:1: 22:2>::new(_1: &std::cell::Cell<usize>) -> std::option::Option<BorrowRef> {\r\n    let mut _0: std::option::Option<BorrowRef>; // return place\r\n    scope 1 {\r\n        let _5: usize;                   // \"b\" in scope 1 at src/main.rs:16:13: 16:14\r\n    }\r\n    let mut _2: usize;\r\n    let mut _3: &std::cell::Cell<usize>;\r\n    let mut _4: u8;\r\n    let mut _6: ();\r\n    let mut _7: &std::cell::Cell<usize>;\r\n    let mut _8: usize;\r\n    let mut _9: usize;\r\n    let mut _10: (usize, bool);\r\n    let mut _11: BorrowRef;\r\n    let mut _12: &std::cell::Cell<usize>;\r\n\r\n    bb0: {                              \r\n        StorageLive(_2);                 // bb0[0]: scope 0 at src/main.rs:14:15: 14:27\r\n        StorageLive(_3);                 // bb0[1]: scope 0 at src/main.rs:14:15: 14:21\r\n        _3 = _1;                         // bb0[2]: scope 0 at src/main.rs:14:15: 14:21\r\n        _2 = const <std::cell::Cell<T>>::get(move _3) -> bb1; // bb0[3]: scope 0 at src/main.rs:14:15: 14:27\r\n                                         // ty::Const\r\n                                         // └ ty: for<'r> fn(&'r std::cell::Cell<usize>) -> usize {<std::cell::Cell<T>><usize>::get}\r\n                                         // └ val: Function(DefId(2/0:1406 ~ core[3d52]::cell[0]::{{impl}}[0]::get[0]), Slice([usize]))\r\n                                         // mir::Constant\r\n                                         // └ span: src/main.rs:14:15: 14:27\r\n                                         // └ ty: for<'r> fn(&'r std::cell::Cell<usize>) -> usize {<std::cell::Cell<T>><usize>::get}\r\n                                         // └ literal: const <std::cell::Cell<T>>::get\r\n    }\r\n\r\n    bb1: {                              \r\n        StorageDead(_3);                 // bb1[0]: scope 0 at src/main.rs:14:27: 14:27\r\n        _4 = discriminant(_2);           // bb1[1]: scope 0 at src/main.rs:14:9: 20:10\r\n        switchInt(_2) -> [18446744073709551615usize: bb2, otherwise: bb3]; // bb1[2]: scope 0 at src/main.rs:15:13: 15:20\r\n    }\r\n\r\n    bb2: {                              \r\n        _0 = std::option::Option<BorrowRef>::None; // bb2[0]: scope 0 at src/main.rs:15:24: 15:28\r\n        goto -> bb4;                     // bb2[1]: scope 0 at src/main.rs:14:9: 20:10\r\n    }\r\n\r\n    bb3: {                              \r\n        StorageLive(_5);                 // bb3[0]: scope 0 at src/main.rs:16:13: 16:14\r\n        _5 = _2;                         // bb3[1]: scope 0 at src/main.rs:16:13: 16:14\r\n        StorageLive(_7);                 // bb3[2]: scope 1 at src/main.rs:17:17: 17:23\r\n        _7 = _1;                         // bb3[3]: scope 1 at src/main.rs:17:17: 17:23\r\n        StorageLive(_8);                 // bb3[4]: scope 1 at src/main.rs:17:28: 17:33\r\n        StorageLive(_9);                 // bb3[5]: scope 1 at src/main.rs:17:28: 17:29\r\n        _9 = _5;                         // bb3[6]: scope 1 at src/main.rs:17:28: 17:29\r\n        _10 = CheckedAdd(move _9, const 1usize); // bb3[7]: scope 1 at src/main.rs:17:28: 17:33\r\n                                         // ty::Const\r\n                                         // └ ty: usize\r\n                                         // └ val: Integral(Usize(Us64(1)))\r\n                                         // mir::Constant\r\n                                         // └ span: src/main.rs:17:32: 17:33\r\n                                         // └ ty: usize\r\n                                         // └ literal: const 1usize\r\n        assert(!move (_10.1: bool), \"attempt to add with overflow\") -> bb5; // bb3[8]: scope 1 at src/main.rs:17:28: 17:33\r\n    }\r\n\r\n    bb4: {                              \r\n        StorageDead(_5);                 // bb4[0]: scope 0 at src/main.rs:20:10: 20:10\r\n        StorageDead(_2);                 // bb4[1]: scope 0 at src/main.rs:21:6: 21:6\r\n        return;                          // bb4[2]: scope 0 at src/main.rs:21:6: 21:6\r\n    }\r\n\r\n    bb5: {                              \r\n        _8 = move (_10.0: usize);        // bb5[0]: scope 1 at src/main.rs:17:28: 17:33\r\n        StorageDead(_9);                 // bb5[1]: scope 1 at src/main.rs:17:33: 17:33\r\n        _6 = const <std::cell::Cell<T>>::set(move _7, move _8) -> bb6; // bb5[2]: scope 1 at src/main.rs:17:17: 17:34\r\n                                         // ty::Const\r\n                                         // └ ty: for<'r> fn(&'r std::cell::Cell<usize>, usize) {<std::cell::Cell<T>><usize>::set}\r\n                                         // └ val: Function(DefId(2/0:1430 ~ core[3d52]::cell[0]::{{impl}}[10]::set[0]), Slice([usize]))\r\n                                         // mir::Constant\r\n                                         // └ span: src/main.rs:17:17: 17:34\r\n                                         // └ ty: for<'r> fn(&'r std::cell::Cell<usize>, usize) {<std::cell::Cell<T>><usize>::set}\r\n                                         // └ literal: const <std::cell::Cell<T>>::set\r\n    }\r\n\r\n    bb6: {                              \r\n        StorageDead(_8);                 // bb6[0]: scope 1 at src/main.rs:17:34: 17:34\r\n        StorageDead(_7);                 // bb6[1]: scope 1 at src/main.rs:17:34: 17:34\r\n        StorageLive(_11);                // bb6[2]: scope 1 at src/main.rs:18:22: 18:50\r\n        StorageLive(_12);                // bb6[3]: scope 1 at src/main.rs:18:42: 18:48\r\n        _12 = _1;                        // bb6[4]: scope 1 at src/main.rs:18:42: 18:48\r\n        _11 = BorrowRef { borrow: move _12 }; // bb6[5]: scope 1 at src/main.rs:18:22: 18:50\r\n        StorageDead(_12);                // bb6[6]: scope 1 at src/main.rs:18:50: 18:50\r\n        _0 = std::option::Option<BorrowRef>::Some(move _11,); // bb6[7]: scope 1 at src/main.rs:18:17: 18:51\r\n        StorageDead(_11);                // bb6[8]: scope 1 at src/main.rs:18:51: 18:51\r\n        goto -> bb4;                     // bb6[9]: scope 0 at src/main.rs:14:9: 20:10\r\n    }\r\n}\r\n```"}}
{"actor":{"display_login":"bjorn3"}}