about summary refs log tree commit diff
diff options
context:
space:
mode:
authoroxalica <oxalicc@pm.me>2022-10-10 16:00:33 +0200
committerest31 <MTest31@outlook.com>2022-10-24 22:05:39 +0200
commit01e651f2feea84ce0b4551a71101f7b29bcc65cb (patch)
treea98dc069e04a67915a03eb7102f7407a9e3dd80c
parenta1db9311dc0ddb0dea68d2661442df2c6f4b382c (diff)
downloadrust-01e651f2feea84ce0b4551a71101f7b29bcc65cb.tar.gz
rust-01e651f2feea84ce0b4551a71101f7b29bcc65cb.zip
Don't lint if the let is already a let-else
We cannot apply the lint for 3-branches like in the added example.
-rw-r--r--clippy_lints/src/manual_let_else.rs1
-rw-r--r--tests/ui/manual_let_else.rs3
2 files changed, 4 insertions, 0 deletions
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!() };
 }