Skip to content

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

Closed
@dtolnay

Description

@dtolnay
#![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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions