Skip to content

Commit 8d75c38

Browse files
oxalicaest31
authored andcommitted
Don't lint if the let is already a let-else
We cannot apply the lint for 3-branches like in the added example.
1 parent e413e4c commit 8d75c38

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

clippy_lints/src/manual_let_else.rs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
7373
if !in_external_macro(cx.sess(), stmt.span);
7474
if let StmtKind::Local(local) = stmt.kind;
7575
if let Some(init) = local.init;
76+
if local.els.is_none();
7677
if init.span.ctxt() == stmt.span.ctxt();
7778
if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init);
7879
then {

tests/ui/manual_let_else.rs

+3
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,7 @@ fn not_fire() {
194194
};
195195
}
196196
create_binding_if_some_nf!(v, g());
197+
198+
// Already a let-else
199+
let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() };
197200
}

0 commit comments

Comments
 (0)