Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_lints/src/if_then_some_else_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/if_then_some_else_none.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
12 changes: 12 additions & 0 deletions tests/ui/if_then_some_else_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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