Auto merge of #10345 - J-ZhengLi:issue_10049, r=xFrednet

fix [`needless_return`] incorrect suggestion when returning if sequence

fixes: #10049

---

changelog: [`needless_return`]: fix incorrect suggestion  on if sequence
This commit is contained in:
bors 2023-02-15 10:27:46 +00:00
commit d3d235dcbf
4 changed files with 103 additions and 47 deletions

View file

@ -297,4 +297,14 @@ fn issue10051() -> Result<String, String> {
}
}
mod issue10049 {
fn single() -> u32 {
if true { 1 } else { 2 }
}
fn multiple(b1: bool, b2: bool, b3: bool) -> u32 {
(if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 })
}
}
fn main() {}

View file

@ -307,4 +307,14 @@ fn issue10051() -> Result<String, String> {
}
}
mod issue10049 {
fn single() -> u32 {
return if true { 1 } else { 2 };
}
fn multiple(b1: bool, b2: bool, b3: bool) -> u32 {
return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
}
}
fn main() {}

View file

@ -418,5 +418,21 @@ LL | return Err(format!("err!"));
|
= help: remove `return`
error: aborting due to 50 previous errors
error: unneeded `return` statement
--> $DIR/needless_return.rs:312:9
|
LL | return if true { 1 } else { 2 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:316:9
|
LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove `return` and wrap the sequence with parentheses
error: aborting due to 52 previous errors