Auto merge of #12851 - samueltardieu:issue12846, r=y21

Add required parentheses around method receiver

Fix #12846

changelog: [`needless_bool`]: Add missing parentheses around method receiver
This commit is contained in:
bors 2024-06-07 21:27:46 +00:00
commit d553ebef57
6 changed files with 65 additions and 15 deletions

View file

@ -131,3 +131,15 @@ fn needless_bool_condition() -> bool {
foo()
}
fn issue12846() {
let a = true;
let b = false;
// parentheses are needed here
let _x = (a && b).then(|| todo!());
let _x = (a && b) as u8;
// parentheses are not needed here
let _x = a.then(|| todo!());
}

View file

@ -191,3 +191,15 @@ fn needless_bool_condition() -> bool {
foo()
}
fn issue12846() {
let a = true;
let b = false;
// parentheses are needed here
let _x = if a && b { true } else { false }.then(|| todo!());
let _x = if a && b { true } else { false } as u8;
// parentheses are not needed here
let _x = if a { true } else { false }.then(|| todo!());
}

View file

@ -191,5 +191,23 @@ error: this if-then-else expression returns a bool literal
LL | if unsafe { no(4) } & 1 != 0 { true } else { false }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
error: aborting due to 21 previous errors
error: this if-then-else expression returns a bool literal
--> tests/ui/needless_bool/fixable.rs:200:14
|
LL | let _x = if a && b { true } else { false }.then(|| todo!());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a && b)`
error: this if-then-else expression returns a bool literal
--> tests/ui/needless_bool/fixable.rs:201:14
|
LL | let _x = if a && b { true } else { false } as u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a && b)`
error: this if-then-else expression returns a bool literal
--> tests/ui/needless_bool/fixable.rs:204:14
|
LL | let _x = if a { true } else { false }.then(|| todo!());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `a`
error: aborting due to 24 previous errors