Skip to content

Incorrect suggestion to remove parentheses around if-condition containing break #54704

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
dtolnay opened this issue Sep 30, 2018 · 0 comments · Fixed by #54885
Closed

Incorrect suggestion to remove parentheses around if-condition containing break #54704

dtolnay opened this issue Sep 30, 2018 · 0 comments · Fixed by #54885
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@dtolnay
Copy link
Member

dtolnay commented Sep 30, 2018

#![allow(unreachable_code)]

fn f() -> bool {
    loop {
        if (break { return true }) {
        }
    }
    false
}

fn g() -> bool {
    loop {
        if break { return true } {
        }
    }
    false
}

fn main() {
    println!("f={} g={}", f(), g());
}
f=true g=false

Rustc 1.30.0-nightly (bb0896a 2018-09-29) suggests turning f into g, which changes the meaning of the program.

```warning: unnecessary parentheses around `if` condition
 --> src/main.rs:5:12
  |
5 |         if (break { return true }) {
  |            ^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
  |
  = note: #[warn(unused_parens)] on by default
@dtolnay dtolnay added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Sep 30, 2018
@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 1, 2018
kennytm added a commit to kennytm/rust that referenced this issue Oct 30, 2018
Don't lint 'unused_parens` on `if (break _) { .. }`

This fixes rust-lang#54704
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants