fix: if_then_some_else_none FP when return exists in block expr
This commit is contained in:
parent
3c93ba0c1d
commit
642feb7e56
3 changed files with 25 additions and 0 deletions
|
|
@ -79,6 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
|
|||
&& !is_in_const_context(cx)
|
||||
&& self.msrv.meets(cx, msrvs::BOOL_THEN)
|
||||
&& !contains_return(then_block.stmts)
|
||||
&& then_block.expr.is_none_or(|expr| !contains_return(expr))
|
||||
{
|
||||
let method_name = if switch_to_eager_eval(cx, expr) && self.msrv.meets(cx, msrvs::BOOL_THEN_SOME) {
|
||||
sym::then_some
|
||||
|
|
|
|||
|
|
@ -206,3 +206,15 @@ fn dont_lint_inside_macros() {
|
|||
}
|
||||
let _: Option<u32> = mac!(true, 42);
|
||||
}
|
||||
|
||||
mod issue15770 {
|
||||
fn maybe_error() -> Result<u32, &'static str> {
|
||||
Err("error!")
|
||||
}
|
||||
|
||||
pub fn trying(b: bool) -> Result<(), &'static str> {
|
||||
let _x: Option<u32> = if b { Some(maybe_error()?) } else { None };
|
||||
// Process _x locally
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,3 +262,15 @@ fn dont_lint_inside_macros() {
|
|||
}
|
||||
let _: Option<u32> = mac!(true, 42);
|
||||
}
|
||||
|
||||
mod issue15770 {
|
||||
fn maybe_error() -> Result<u32, &'static str> {
|
||||
Err("error!")
|
||||
}
|
||||
|
||||
pub fn trying(b: bool) -> Result<(), &'static str> {
|
||||
let _x: Option<u32> = if b { Some(maybe_error()?) } else { None };
|
||||
// Process _x locally
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue