Skip to content

Commit 4a9b8c6

Browse files
authored
fix: map_entry FP inside closure (rust-lang#14307)
Closes rust-lang#11976 changelog: [`map_entry`]: fix FP inside closure
2 parents 527ab05 + 329acde commit 4a9b8c6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

clippy_lints/src/entry.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
use core::fmt::{self, Write};
99
use rustc_errors::Applicability;
1010
use rustc_hir::hir_id::HirIdSet;
11-
use rustc_hir::intravisit::{Visitor, walk_expr};
11+
use rustc_hir::intravisit::{Visitor, walk_body, walk_expr};
1212
use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp};
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_session::declare_lint_pass;
@@ -331,7 +331,7 @@ impl<'tcx> Edit<'tcx> {
331331
if let Self::Insertion(i) = self { Some(i) } else { None }
332332
}
333333
}
334-
#[derive(Clone, Copy)]
334+
#[derive(Clone, Copy, Debug)]
335335
struct Insertion<'tcx> {
336336
call: &'tcx Expr<'tcx>,
337337
value: &'tcx Expr<'tcx>,
@@ -544,6 +544,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
544544
ExprKind::InlineAsm(_) => {
545545
self.can_use_entry = false;
546546
},
547+
ExprKind::Closure(closure) => walk_body(self, self.cx.tcx.hir_body(closure.body)),
547548
_ => {
548549
self.allow_insert_closure &= !self.in_tail_pos;
549550
self.allow_insert_closure &=

tests/ui/entry.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,12 @@ mod issue13934 {
218218
}
219219
}
220220

221+
fn issue11976() {
222+
let mut hashmap = std::collections::HashMap::new();
223+
if !hashmap.contains_key(&0) {
224+
let _ = || hashmap.get(&0);
225+
hashmap.insert(0, 0);
226+
}
227+
}
228+
221229
fn main() {}

tests/ui/entry.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,12 @@ mod issue13934 {
224224
}
225225
}
226226

227+
fn issue11976() {
228+
let mut hashmap = std::collections::HashMap::new();
229+
if !hashmap.contains_key(&0) {
230+
let _ = || hashmap.get(&0);
231+
hashmap.insert(0, 0);
232+
}
233+
}
234+
227235
fn main() {}

0 commit comments

Comments
 (0)