{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust-clippy/issues/3559","repository_url":"https://api.github.com/repos/rust-lang/rust-clippy","labels_url":"https://api.github.com/repos/rust-lang/rust-clippy/issues/3559/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust-clippy/issues/3559/comments","events_url":"https://api.github.com/repos/rust-lang/rust-clippy/issues/3559/events","html_url":"https://github.com/rust-lang/rust-clippy/issues/3559","id":392052519,"node_id":"MDU6SXNzdWUzOTIwNTI1MTk=","number":3559,"title":"False positive for `if_same_then_else`","user":{"login":"Vzaa","id":1405886,"node_id":"MDQ6VXNlcjE0MDU4ODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1405886?v=4","gravatar_id":"","url":"https://api.github.com/users/Vzaa","html_url":"https://github.com/Vzaa","followers_url":"https://api.github.com/users/Vzaa/followers","following_url":"https://api.github.com/users/Vzaa/following{/other_user}","gists_url":"https://api.github.com/users/Vzaa/gists{/gist_id}","starred_url":"https://api.github.com/users/Vzaa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vzaa/subscriptions","organizations_url":"https://api.github.com/users/Vzaa/orgs","repos_url":"https://api.github.com/users/Vzaa/repos","events_url":"https://api.github.com/users/Vzaa/events{/privacy}","received_events_url":"https://api.github.com/users/Vzaa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-18T08:51:23Z","updated_at":"2018-12-18T08:56:06Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nHi there! Whether you've come to make a suggestion for a new lint, an improvement to an existing lint or to report a bug or a false positive in Clippy, you've come to the right place.\r\n\r\nFor bug reports and false positives, please include the output of `cargo clippy -V` in the report.\r\n\r\nThank you for using Clippy!\r\n\r\nWrite your comment below this line: -->\r\nHello,\r\n\r\nI was using clippy to check some code I wrote for advent of code 2018 and I believe I have a false positive for `if_same_then_else`.\r\n\r\nThe piece of code I get the error for:\r\n\r\n```rust\r\nuse std::collections::HashSet;\r\n\r\nfn main() {\r\n    let text = \"x\\ny\\n\";\r\n    let mut clays = HashSet::new();\r\n\r\n    for line in text.lines() {\r\n        let (from, to, p) = (10, 20, 10);\r\n\r\n        if line.starts_with('x') {\r\n            let x = p;\r\n            for y in from..=to {\r\n                clays.insert((x, y));\r\n            }\r\n        } else if line.starts_with('y') {\r\n            let y = p;\r\n            for x in from..=to {\r\n                clays.insert((x, y));\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n```\r\n`cargo clippy` output:\r\n\r\n```\r\n$ cargo clippy                                                                                                                                                                                                                      (master ?)\r\n    Checking cl v0.1.0 (/tmp/cl)                                                                                                                                                                                                               \r\nerror: this `if` has identical blocks                                                                                                                                                                                                          \r\n  --> src/main.rs:15:41                                                                                                                                                                                                                        \r\n   |                                                                                                                                                                                                                                           \r\n15 |           } else if line.starts_with('y') {                                                                                                                                                                                               \r\n   |  _________________________________________^                                                                                                                                                                                               \r\n16 | |             let y = p;                                                                                                                                                                                                                  \r\n17 | |             for x in from..=to {                                                                                                                                                                                                        \r\n18 | |                 clays.insert((x, y));                                                                                                                                                                                                   \r\n19 | |             }                                                                                                                                                                                                                           \r\n20 | |         }                                                                                                                                                                                                                               \r\n   | |_________^                                                                                                                                                                                                                               \r\n   |                                                                                                                                                                                                                                           \r\n   = note: #[deny(clippy::if_same_then_else)] on by default                                                                                                                                                                                    \r\nnote: same as this                                                                                                                                                                                                                             \r\n  --> src/main.rs:10:34                                                                                                                                                                                                                        \r\n   |                                                                                                                                                                                                                                           \r\n10 |           if line.starts_with('x') {                                                                                                                                                                                                      \r\n   |  __________________________________^                                                                                                                                                                                                      \r\n11 | |             let x = p;                                                                                                                                                                                                                  \r\n12 | |             for y in from..=to {                                                                                                                                                                                                        \r\n13 | |                 clays.insert((x, y));                                                                                                                                                                                                   \r\n14 | |             }                                                                                                                                                                                                                           \r\n15 | |         } else if line.starts_with('y') {                                                                                                                                                                                               \r\n   | |_________^                                                                                                                                                                                                                               \r\n   = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#if_same_then_else                                                                                                                   \r\n                                                                                                                                                                                                                                               \r\nerror: aborting due to previous error                                                                                                                                                                                                          \r\n                                                                                                                                                                                                                                               \r\nerror: Could not compile `cl`.   \r\n```\r\n\r\nIn the code it either iterates from`from` to `to` for x or y while p determines the stationary point. The blocks actually have different outcomes.\r\n\r\n`cargo clippy -V` output:\r\n\r\n```\r\n$ cargo clippy -V                                                                                                                                                                                                                   (master ?)\r\nclippy 0.0.212 (2e26fdc 2018-11-22)\r\n```\r\nThe same error is reported on the version on Rust Playground:\r\n[Playground Link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=189a8178b0d498f84260862a9c763c3d\r\n)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust-clippy/issues/comments/448144942","html_url":"https://github.com/rust-lang/rust-clippy/issues/3559#issuecomment-448144942","issue_url":"https://api.github.com/repos/rust-lang/rust-clippy/issues/3559","id":448144942,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODE0NDk0Mg==","user":{"login":"thomwiggers","id":974662,"node_id":"MDQ6VXNlcjk3NDY2Mg==","avatar_url":"https://avatars1.githubusercontent.com/u/974662?v=4","gravatar_id":"","url":"https://api.github.com/users/thomwiggers","html_url":"https://github.com/thomwiggers","followers_url":"https://api.github.com/users/thomwiggers/followers","following_url":"https://api.github.com/users/thomwiggers/following{/other_user}","gists_url":"https://api.github.com/users/thomwiggers/gists{/gist_id}","starred_url":"https://api.github.com/users/thomwiggers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomwiggers/subscriptions","organizations_url":"https://api.github.com/users/thomwiggers/orgs","repos_url":"https://api.github.com/users/thomwiggers/repos","events_url":"https://api.github.com/users/thomwiggers/events{/privacy}","received_events_url":"https://api.github.com/users/thomwiggers/received_events","type":"User","site_admin":false},"created_at":"2018-12-18T08:56:06Z","updated_at":"2018-12-18T08:56:06Z","author_association":"NONE","body":"If you substitute the `let x` and `let y` into the tuple, clippy won't complain:\r\n\r\n```rust\r\nuse std::collections::HashSet;\r\n\r\nfn main() {\r\n    let text = \"x\\ny\\n\";\r\n    let mut clays = HashSet::new();\r\n\r\n    for line in text.lines() {\r\n        let (from, to, p) = (10, 20, 10);\r\n\r\n        if line.starts_with('x') {\r\n            for y in from..=to {\r\n                clays.insert((p, y));\r\n            }\r\n        } else if line.starts_with('y') {\r\n            for x in from..=to {\r\n                clays.insert((x, p));\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\n([Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=39312a6f8c50e696952582e0dc563567))\r\n"}}
{"actor":{"display_login":"thomwiggers"}}