{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/53528","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/53528/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/53528/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/53528/events","html_url":"https://github.com/rust-lang/rust/issues/53528","id":352145813,"node_id":"MDU6SXNzdWUzNTIxNDU4MTM=","number":53528,"title":"NLL + impl Trait: Borrow checker error on else branch","user":{"login":"andreytkachenko","id":1773973,"node_id":"MDQ6VXNlcjE3NzM5NzM=","avatar_url":"https://avatars3.githubusercontent.com/u/1773973?v=4","gravatar_id":"","url":"https://api.github.com/users/andreytkachenko","html_url":"https://github.com/andreytkachenko","followers_url":"https://api.github.com/users/andreytkachenko/followers","following_url":"https://api.github.com/users/andreytkachenko/following{/other_user}","gists_url":"https://api.github.com/users/andreytkachenko/gists{/gist_id}","starred_url":"https://api.github.com/users/andreytkachenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreytkachenko/subscriptions","organizations_url":"https://api.github.com/users/andreytkachenko/orgs","repos_url":"https://api.github.com/users/andreytkachenko/repos","events_url":"https://api.github.com/users/andreytkachenko/events{/privacy}","received_events_url":"https://api.github.com/users/andreytkachenko/received_events","type":"User","site_admin":false},"labels":[{"id":604489711,"node_id":"MDU6TGFiZWw2MDQ0ODk3MTE=","url":"https://api.github.com/repos/rust-lang/rust/labels/A-NLL","name":"A-NLL","color":"d7e102","default":false},{"id":203429200,"node_id":"MDU6TGFiZWwyMDM0MjkyMDA=","url":"https://api.github.com/repos/rust-lang/rust/labels/P-high","name":"P-high","color":"eb6420","default":false},{"id":211668100,"node_id":"MDU6TGFiZWwyMTE2NjgxMDA=","url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":{"login":"pnkfelix","id":173127,"node_id":"MDQ6VXNlcjE3MzEyNw==","avatar_url":"https://avatars0.githubusercontent.com/u/173127?v=4","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},"assignees":[{"login":"pnkfelix","id":173127,"node_id":"MDQ6VXNlcjE3MzEyNw==","avatar_url":"https://avatars0.githubusercontent.com/u/173127?v=4","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}],"milestone":{"url":"https://api.github.com/repos/rust-lang/rust/milestones/56","html_url":"https://github.com/rust-lang/rust/milestone/56","labels_url":"https://api.github.com/repos/rust-lang/rust/milestones/56/labels","id":3537666,"node_id":"MDk6TWlsZXN0b25lMzUzNzY2Ng==","number":56,"title":"Edition 2018 RC 2","description":"","creator":{"login":"Mark-Simulacrum","id":5047365,"node_id":"MDQ6VXNlcjUwNDczNjU=","avatar_url":"https://avatars0.githubusercontent.com/u/5047365?v=4","gravatar_id":"","url":"https://api.github.com/users/Mark-Simulacrum","html_url":"https://github.com/Mark-Simulacrum","followers_url":"https://api.github.com/users/Mark-Simulacrum/followers","following_url":"https://api.github.com/users/Mark-Simulacrum/following{/other_user}","gists_url":"https://api.github.com/users/Mark-Simulacrum/gists{/gist_id}","starred_url":"https://api.github.com/users/Mark-Simulacrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mark-Simulacrum/subscriptions","organizations_url":"https://api.github.com/users/Mark-Simulacrum/orgs","repos_url":"https://api.github.com/users/Mark-Simulacrum/repos","events_url":"https://api.github.com/users/Mark-Simulacrum/events{/privacy}","received_events_url":"https://api.github.com/users/Mark-Simulacrum/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":4,"state":"open","created_at":"2018-07-31T22:51:05Z","updated_at":"2018-09-11T19:34:33Z","due_on":"2018-10-25T07:00:00Z","closed_at":null},"comments":5,"created_at":"2018-08-20T13:53:42Z","updated_at":"2018-09-13T11:06:11Z","closed_at":null,"author_association":"NONE","body":"Here is an example:\r\n```rust\r\n#![feature(nll)]\r\n\r\n#[derive(Default)]\r\nstruct X(Vec<u32>);\r\n\r\nimpl X {\r\n    // error will gone if uncomment\r\n    // fn get_iter(&self) -> Option<std::slice::Iter<'_, u32>> {\r\n    fn get_iter(&self) -> Option<impl Iterator<Item = &u32>> { \r\n        Some(self.0.iter())\r\n    }\r\n    \r\n    fn push(&mut self, x: u32) {\r\n        self.0.push(x);\r\n    }\r\n}\r\n\r\nfn main() {\r\n    let mut tmp = X::default();\r\n\r\n    if let Some(xx) = tmp.get_iter() { // `xx` holds the reference to `tmp`\r\n        for t in xx {\r\n            println!(\"{:?}\", t);\r\n        }\r\n\r\n        // but here `xx` is dropped\r\n    } else {\r\n        tmp.push(1); // ERROR: cannot borrow `tmp` as mutable because it is also borrowed as immutable\r\n        // why tmp is still borrowed here?\r\n    };\r\n}\r\n```\r\nhere is the error:\r\n```\r\nerror[E0502]: cannot borrow `tmp` as mutable because it is also borrowed as immutable\r\n  --> src/main.rs:26:9\r\n   |\r\n19 |     if let Some(xx) = tmp.get_iter() { // `xx` holds the reference to `tmp`\r\n   |                       --- immutable borrow occurs here\r\n...\r\n26 |         tmp.push(1); // ERROR: cannot borrow `tmp` as mutable because it is also borrowed as immutable\r\n   |         ^^^^^^^^^^^ mutable borrow occurs here\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/420969635","html_url":"https://github.com/rust-lang/rust/issues/53528#issuecomment-420969635","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/53528","id":420969635,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDk2OTYzNQ==","user":{"login":"pnkfelix","id":173127,"node_id":"MDQ6VXNlcjE3MzEyNw==","avatar_url":"https://avatars0.githubusercontent.com/u/173127?v=4","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":"2018-09-13T11:06:11Z","updated_at":"2018-09-13T11:06:11Z","author_association":"MEMBER","body":"and likewise here is that same workaround being applied to the original example ([play](https://play.rust-lang.org/?gist=f142326da52422cb2e5cd1d5f8bbff8c&version=nightly&mode=debug&edition=2015)):\r\n\r\n```rust\r\n#![feature(nll)]\r\n\r\n#[derive(Default)]\r\nstruct X(Vec<u32>);\r\n\r\nimpl X {\r\n    // error will gone if uncomment\r\n    // fn get_iter(&self) -> Option<std::slice::Iter<'_, u32>> {\r\n    fn get_iter(&self) -> Option<impl Iterator<Item = &u32>> {\r\n        Some(self.0.iter())\r\n    }\r\n    \r\n    fn push(&mut self, x: u32) {\r\n        self.0.push(x);\r\n    }\r\n}\r\n\r\nfn main() {\r\n    let mut tmp = X::default();\r\n\r\n    match tmp.get_iter() { // `xx` holds the reference to `tmp`\r\n        Some(xx) => {\r\n            for t in xx {\r\n                println!(\"{:?}\", t);\r\n            }\r\n        }\r\n        xx @ None => {\r\n            drop(xx);\r\n            tmp.push(1);\r\n        }\r\n    };\r\n}\r\n```"}}
{"actor":{"display_login":"pnkfelix"}}