mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
fix: if_then_some_else_none FP when return exists in block expr
This commit is contained in:
@@ -79,6 +79,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
&& !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 @@ macro_rules! mac {
|
||||
}
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user