]> git.lizzy.rs Git - rust.git/commitdiff
Don't fire the lint if there is a type annotation
authorest31 <MTest31@outlook.com>
Mon, 10 Oct 2022 19:51:24 +0000 (21:51 +0200)
committerest31 <MTest31@outlook.com>
Mon, 24 Oct 2022 20:05:39 +0000 (22:05 +0200)
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.

clippy_lints/src/manual_let_else.rs
tests/ui/manual_let_else.rs

index 8a915127c3c6729d1655ae8c670bd8f16a72b6e0..521d02db80fb827d86d81107871fa025a249f430 100644 (file)
@@ -74,6 +74,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &'tcx Stmt<'tcx>) {
             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 {
index 9e5df65b74d37938f84e1ebe7c79db5e01e73fe7..9046c0affb591bb54b387b34346f68de50dadeb9 100644 (file)
@@ -197,4 +197,8 @@ macro_rules! create_binding_if_some_nf {
 
     // 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!() };
 }