diff options
| author | est31 <MTest31@outlook.com> | 2022-10-10 21:51:24 +0200 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2022-10-24 22:05:39 +0200 |
| commit | 748169deaa3c57e15e3a84bb90e033dddaa64e03 (patch) | |
| tree | 264cdc281a8d1f03a46545d5e69ea9789dff2b8d | |
| parent | 01e651f2feea84ce0b4551a71101f7b29bcc65cb (diff) | |
| download | rust-748169deaa3c57e15e3a84bb90e033dddaa64e03.tar.gz rust-748169deaa3c57e15e3a84bb90e033dddaa64e03.zip | |
Don't fire the lint if there is a type annotation
Sometimes type annotations are needed for type inferrence to work, or because of coercions. We don't know this, and we also don't want users to possibly repeat the entire pattern.
| -rw-r--r-- | clippy_lints/src/manual_let_else.rs | 1 | ||||
| -rw-r--r-- | tests/ui/manual_let_else.rs | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index 8a915127c3c..521d02db80f 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -74,6 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse { if let StmtKind::Local(local) = stmt.kind; if let Some(init) = local.init; if local.els.is_none(); + if local.ty.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 9e5df65b74d..9046c0affb5 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -197,4 +197,8 @@ fn not_fire() { // Already a let-else let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() }; + + // If a type annotation is present, don't lint as + // expressing the type might be too hard + let v: () = if let Some(v_some) = g() { v_some } else { panic!() }; } |
