{"action":"created","issue":{"url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/506","labels_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/506/labels{/name}","comments_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/506/comments","events_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/506/events","html_url":"https://github.com/Manishearth/rust-clippy/pull/506","id":122701654,"number":506,"title":"Lint for pointing out needless continue statements, fixes #111","user":{"login":"yati-sagade","id":966274,"avatar_url":"https://avatars.githubusercontent.com/u/966274?v=3","gravatar_id":"","url":"https://api.github.com/users/yati-sagade","html_url":"https://github.com/yati-sagade","followers_url":"https://api.github.com/users/yati-sagade/followers","following_url":"https://api.github.com/users/yati-sagade/following{/other_user}","gists_url":"https://api.github.com/users/yati-sagade/gists{/gist_id}","starred_url":"https://api.github.com/users/yati-sagade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yati-sagade/subscriptions","organizations_url":"https://api.github.com/users/yati-sagade/orgs","repos_url":"https://api.github.com/users/yati-sagade/repos","events_url":"https://api.github.com/users/yati-sagade/events{/privacy}","received_events_url":"https://api.github.com/users/yati-sagade/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-17T10:03:21Z","updated_at":"2015-12-17T12:08:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Manishearth/rust-clippy/pulls/506","html_url":"https://github.com/Manishearth/rust-clippy/pull/506","diff_url":"https://github.com/Manishearth/rust-clippy/pull/506.diff","patch_url":"https://github.com/Manishearth/rust-clippy/pull/506.patch"},"body":"This lint deals with two separate cases of needless `continue` statements.\r\n\r\n#### Case 1: continue is the first/only statement in the `else` block in a loop\r\n    loop {\r\n        // region A\r\n        if cond {\r\n            // region B\r\n        } else {\r\n            continue;\r\n        }\r\n        // region C\r\n    }\r\n\r\nHere, `C` can be merged with `B` and the `else` block can be thrown away:\r\n\r\n    loop {\r\n        // region A\r\n        if cond {\r\n            // region B\r\n            // region C\r\n        }\r\n    }\r\n\r\n#### Case 2: continue is the first/only statement in the `if` block in a loop\r\n\r\n    loop {\r\n        // region A\r\n        if cond {\r\n            continue;\r\n            // potentially more code here.\r\n        } else {\r\n            // region B\r\n        }\r\n        // region C\r\n    }\r\n\r\nHere, we can negate the if condition `cond` and then merge `B` and `C` in the `if` block:\r\n\r\n    loop {\r\n        // region A\r\n        if !cond {\r\n            // region B\r\n            // region C\r\n        }\r\n    }\r\n\r\nThis lint simplifies the negated condition expression by applying comparison operator inversions and de Morgan's laws for logical operations. Maybe this can be moved into a lint by itself.\r\n\r\n[EDIT]\r\nI have my own function for indentation trimming because the one in `utils` did not work for me, and I did not want to change it to break other lints that might be depending on it. Also have a function for aligning code snippets such that the last line of the first snippet aligns with the first line of the second. Maybe we can add this to `utils`."},"comment":{"url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/comments/165436415","html_url":"https://github.com/Manishearth/rust-clippy/pull/506#issuecomment-165436415","issue_url":"https://api.github.com/repos/Manishearth/rust-clippy/issues/506","id":165436415,"user":{"login":"yati-sagade","id":966274,"avatar_url":"https://avatars.githubusercontent.com/u/966274?v=3","gravatar_id":"","url":"https://api.github.com/users/yati-sagade","html_url":"https://github.com/yati-sagade","followers_url":"https://api.github.com/users/yati-sagade/followers","following_url":"https://api.github.com/users/yati-sagade/following{/other_user}","gists_url":"https://api.github.com/users/yati-sagade/gists{/gist_id}","starred_url":"https://api.github.com/users/yati-sagade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yati-sagade/subscriptions","organizations_url":"https://api.github.com/users/yati-sagade/orgs","repos_url":"https://api.github.com/users/yati-sagade/repos","events_url":"https://api.github.com/users/yati-sagade/events{/privacy}","received_events_url":"https://api.github.com/users/yati-sagade/received_events","type":"User","site_admin":false},"created_at":"2015-12-17T12:08:15Z","updated_at":"2015-12-17T12:08:15Z","body":"Yes, I tried using borrows of `Expr`s when possible, but since `P` owns its resident, it seems impossible. I'm was worried about the effect this and the `String` creations could have on the compile time. But frankly, it's not that noticeable."}}