about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryanglsh <yanglsh@shanghaitech.edu.cn>2025-02-27 16:20:29 +0800
committeryanglsh <yanglsh@shanghaitech.edu.cn>2025-02-27 21:28:00 +0800
commit329acde93e357e9797dc14aec9503b1f9234dfc9 (patch)
treeac539c25fcae85354e3f3e26b7606a3eef86377a
parent52bf26e9ad2891fda366d2e7e90bbe96be0715e5 (diff)
downloadrust-329acde93e357e9797dc14aec9503b1f9234dfc9.tar.gz
rust-329acde93e357e9797dc14aec9503b1f9234dfc9.zip
fix: `map_entry` FP inside closure
-rw-r--r--clippy_lints/src/entry.rs5
-rw-r--r--tests/ui/entry.fixed8
-rw-r--r--tests/ui/entry.rs8
3 files changed, 19 insertions, 2 deletions
diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs
index f8a5cf53cda..f404bc59b3b 100644
--- a/clippy_lints/src/entry.rs
+++ b/clippy_lints/src/entry.rs
@@ -8,7 +8,7 @@ use clippy_utils::{
 use core::fmt::{self, Write};
 use rustc_errors::Applicability;
 use rustc_hir::hir_id::HirIdSet;
-use rustc_hir::intravisit::{Visitor, walk_expr};
+use rustc_hir::intravisit::{Visitor, walk_body, walk_expr};
 use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::declare_lint_pass;
@@ -331,7 +331,7 @@ impl<'tcx> Edit<'tcx> {
         if let Self::Insertion(i) = self { Some(i) } else { None }
     }
 }
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
 struct Insertion<'tcx> {
     call: &'tcx Expr<'tcx>,
     value: &'tcx Expr<'tcx>,
@@ -544,6 +544,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
                 ExprKind::InlineAsm(_) => {
                     self.can_use_entry = false;
                 },
+                ExprKind::Closure(closure) => walk_body(self, self.cx.tcx.hir_body(closure.body)),
                 _ => {
                     self.allow_insert_closure &= !self.in_tail_pos;
                     self.allow_insert_closure &=
diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed
index d52299306fd..69452a8d9a6 100644
--- a/tests/ui/entry.fixed
+++ b/tests/ui/entry.fixed
@@ -218,4 +218,12 @@ mod issue13934 {
     }
 }
 
+fn issue11976() {
+    let mut hashmap = std::collections::HashMap::new();
+    if !hashmap.contains_key(&0) {
+        let _ = || hashmap.get(&0);
+        hashmap.insert(0, 0);
+    }
+}
+
 fn main() {}
diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs
index 25cd6eaa413..3578324f01c 100644
--- a/tests/ui/entry.rs
+++ b/tests/ui/entry.rs
@@ -224,4 +224,12 @@ mod issue13934 {
     }
 }
 
+fn issue11976() {
+    let mut hashmap = std::collections::HashMap::new();
+    if !hashmap.contains_key(&0) {
+        let _ = || hashmap.get(&0);
+        hashmap.insert(0, 0);
+    }
+}
+
 fn main() {}