rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.53k stars 12.74k forks source link

false positive for `unused_parens` in a let-else #131655

Open its-the-shrimp opened 1 month ago

its-the-shrimp commented 1 month ago

Code

fn main() {
    macro_rules! x {
        () => { None::<i32> };
    }

    let Some(_x) = (x! {}) else { return };
}

Current output

warning: unnecessary parentheses around assigned value
 --> src/main.rs:6:20
  |
6 |     let Some(_x) = (x! {}) else { return };
  |                    ^     ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
6 -     let Some(_x) = (x! {}) else { return };
6 +     let Some(_x) = x! {} else { return };
  |

warning: 1 warning emitted

Desired output

nothing

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.83.0-nightly (6b9676b45 2024-10-12) binary: rustc commit-hash: 6b9676b45431a1e531b9c5f7bd289fc36a312749 commit-date: 2024-10-12 host: aarch64-apple-darwin release: 1.83.0-nightly LLVM version: 19.1.1

Anything else?

This was an issue on a nightly from 7th of August as well

ChrisDenton commented 1 month ago

I think it should suggest:

let Some(_x) = x!() else { return };
its-the-shrimp commented 1 month ago

I think it should suggest:

let Some(_x) = x!() else { return };

different macros have different implications in regards to what parentheses are to be used with them, it shouldn't be a concern of the compiler