From 01e651f2feea84ce0b4551a71101f7b29bcc65cb Mon Sep 17 00:00:00 2001 From: oxalica Date: Mon, 10 Oct 2022 16:00:33 +0200 Subject: [PATCH] Don't lint if the let is already a let-else We cannot apply the lint for 3-branches like in the added example. --- clippy_lints/src/manual_let_else.rs | 1 + tests/ui/manual_let_else.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index 8d743c86d6d..8a915127c3c 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -73,6 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse { if !in_external_macro(cx.sess(), stmt.span); if let StmtKind::Local(local) = stmt.kind; if let Some(init) = local.init; + if local.els.is_none(); if init.span.ctxt() == stmt.span.ctxt(); if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init); then { diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index bd0ac69e46e..9e5df65b74d 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -194,4 +194,7 @@ fn not_fire() { }; } create_binding_if_some_nf!(v, g()); + + // Already a let-else + let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() }; }