Skip to content

Commit 5e4a1de

Browse files
committed
question_mark: Ignore ifs with else branches
1 parent eb54c1a commit 5e4a1de

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clippy_lints/src/question_mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Pass {
6464
/// If it matches, it will suggest to use the question mark operator instead
6565
fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr) {
6666
if_chain! {
67-
if let ExprKind::If(ref if_expr, ref body, _) = expr.node;
67+
if let ExprKind::If(ref if_expr, ref body, None) = expr.node;
6868
if let ExprKind::MethodCall(ref segment, _, ref args) = if_expr.node;
6969
if segment.ident.name == "is_none";
7070
if Self::expression_returns_none(cx, body);

tests/ui/question_mark.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ impl SomeStruct {
4747
return None;
4848
}
4949

50+
// OK if `else` branch exists.
51+
let _ = if (self.opt).is_none() {
52+
return None;
53+
} else {
54+
self.opt
55+
};
56+
5057
self.opt
5158
}
5259
}

0 commit comments

Comments
 (0)