Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5a13a93

Browse files
committed
[Clippy] Swap map_entry to use diagnostic items instead of paths
1 parent 978582b commit 5a13a93

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

clippy_lints/src/entry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context};
33
use clippy_utils::{
4-
can_move_expr_to_closure_no_visit, higher, is_expr_final_block_expr, is_expr_used_or_unified, match_def_path,
5-
paths, peel_hir_expr_while, SpanlessEq,
4+
can_move_expr_to_closure_no_visit, higher, is_expr_final_block_expr, is_expr_used_or_unified,
5+
peel_hir_expr_while, SpanlessEq,
66
};
77
use core::fmt::{self, Write};
88
use rustc_errors::Applicability;
@@ -11,7 +11,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
1111
use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_session::declare_lint_pass;
14-
use rustc_span::{Span, SyntaxContext, DUMMY_SP};
14+
use rustc_span::{sym, Span, SyntaxContext, DUMMY_SP};
1515

1616
declare_clippy_lint! {
1717
/// ### What it does
@@ -269,9 +269,9 @@ fn try_parse_contains<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Optio
269269
key,
270270
call_ctxt: expr.span.ctxt(),
271271
};
272-
if match_def_path(cx, id, &paths::BTREEMAP_CONTAINS_KEY) {
272+
if cx.tcx.is_diagnostic_item(sym::btreemap_contains_key, id) {
273273
Some((MapType::BTree, expr))
274-
} else if match_def_path(cx, id, &paths::HASHMAP_CONTAINS_KEY) {
274+
} else if cx.tcx.is_diagnostic_item(sym::hashmap_contains_key, id) {
275275
Some((MapType::Hash, expr))
276276
} else {
277277
None
@@ -306,7 +306,7 @@ struct InsertExpr<'tcx> {
306306
fn try_parse_insert<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<InsertExpr<'tcx>> {
307307
if let ExprKind::MethodCall(_, map, [key, value], _) = expr.kind {
308308
let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
309-
if match_def_path(cx, id, &paths::BTREEMAP_INSERT) || match_def_path(cx, id, &paths::HASHMAP_INSERT) {
309+
if cx.tcx.is_diagnostic_item(sym::btreemap_insert, id) || cx.tcx.is_diagnostic_item(sym::hashmap_insert, id) {
310310
Some(InsertExpr { map, key, value })
311311
} else {
312312
None

clippy_utils/src/paths.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
1212
["rustc_lint_defs", "Applicability", "MachineApplicable"],
1313
];
1414
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
15-
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];
16-
pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"];
1715
pub const CORE_RESULT_OK_METHOD: [&str; 4] = ["core", "result", "Result", "ok"];
1816
pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"];
1917
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
@@ -25,8 +23,6 @@ pub const FILE_OPTIONS: [&str; 4] = ["std", "fs", "File", "options"];
2523
pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"];
2624
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
2725
pub const FUTURES_IO_ASYNCWRITEEXT: [&str; 3] = ["futures_util", "io", "AsyncWriteExt"];
28-
pub const HASHMAP_CONTAINS_KEY: [&str; 6] = ["std", "collections", "hash", "map", "HashMap", "contains_key"];
29-
pub const HASHMAP_INSERT: [&str; 6] = ["std", "collections", "hash", "map", "HashMap", "insert"];
3026
pub const HASHMAP_ITER: [&str; 5] = ["std", "collections", "hash", "map", "Iter"];
3127
pub const HASHMAP_ITER_MUT: [&str; 5] = ["std", "collections", "hash", "map", "IterMut"];
3228
pub const HASHMAP_KEYS: [&str; 5] = ["std", "collections", "hash", "map", "Keys"];

0 commit comments

Comments
 (0)