Skip to content

Commit c3acaf3

Browse files
committed
More diagnostic items
In particular for: * `VecDeque` * `String` * `Mutex` * `HashMap` * `HashSet` cc rust-lang/rust#71414 #5393
1 parent d01a498 commit c3acaf3

15 files changed

+57
-52
lines changed

clippy_lints/src/entry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::SpanlessEq;
2-
use crate::utils::{get_item_name, higher, match_type, paths, snippet, snippet_opt};
2+
use crate::utils::{get_item_name, higher, is_type_diagnostic_item, match_type, paths, snippet, snippet_opt};
33
use crate::utils::{snippet_with_applicability, span_lint_and_then, walk_ptrs_ty};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
@@ -114,7 +114,7 @@ fn check_cond<'a, 'tcx, 'b>(
114114
return if match_type(cx, obj_ty, &paths::BTREEMAP) {
115115
Some(("BTreeMap", map, key))
116116
}
117-
else if match_type(cx, obj_ty, &paths::HASHMAP) {
117+
else if is_type_diagnostic_item(cx, obj_ty, sym!(hashmap_type)) {
118118
Some(("HashMap", map, key))
119119
}
120120
else {

clippy_lints/src/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::paths;
22
use crate::utils::{
3-
is_expn_of, last_path_segment, match_def_path, match_function_call, match_type, snippet, span_lint_and_then,
3+
is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet, span_lint_and_then,
44
walk_ptrs_ty,
55
};
66
use if_chain::if_chain;
@@ -91,7 +91,7 @@ fn on_argumentv1_new<'a, 'tcx>(
9191
if pats.len() == 1;
9292
then {
9393
let ty = walk_ptrs_ty(cx.tables.pat_ty(&pats[0]));
94-
if ty.kind != rustc_middle::ty::Str && !match_type(cx, ty, &paths::STRING) {
94+
if ty.kind != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) {
9595
return None;
9696
}
9797
if let ExprKind::Lit(ref lit) = format_args.kind {

clippy_lints/src/if_let_mutex.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_type, paths, span_lint_and_help, SpanlessEq};
1+
use crate::utils::{is_type_diagnostic_item, span_lint_and_help, SpanlessEq};
22
use if_chain::if_chain;
33
use rustc_hir::intravisit::{self as visit, NestedVisitorMap, Visitor};
44
use rustc_hir::{Expr, ExprKind, MatchSource};
@@ -150,7 +150,7 @@ fn is_mutex_lock_call<'a>(cx: &LateContext<'a, '_>, expr: &'a Expr<'_>) -> Optio
150150
if let ExprKind::MethodCall(path, _span, args) = &expr.kind;
151151
if path.ident.to_string() == "lock";
152152
let ty = cx.tables.expr_ty(&args[0]);
153-
if match_type(cx, ty, &paths::MUTEX);
153+
if is_type_diagnostic_item(cx, ty, sym!(mutex_type));
154154
then {
155155
Some(&args[0])
156156
} else {

clippy_lints/src/inherent_to_string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55

66
use crate::utils::{
7-
get_trait_def_id, implements_trait, match_type, paths, return_ty, span_lint_and_help, trait_ref_of_method,
7+
get_trait_def_id, is_type_diagnostic_item, implements_trait, paths, return_ty, span_lint_and_help, trait_ref_of_method,
88
walk_ptrs_ty,
99
};
1010

@@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
107107
if decl.inputs.len() == 1;
108108

109109
// Check if return type is String
110-
if match_type(cx, return_ty(cx, impl_item.hir_id), &paths::STRING);
110+
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym!(string_type));
111111

112112
// Filters instances of to_string which are required by a trait
113113
if trait_ref_of_method(cx, impl_item.hir_id).is_none();

clippy_lints/src/loops.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
804804
_ => false,
805805
};
806806

807-
is_slice || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || match_type(cx, ty, &paths::VEC_DEQUE)
807+
is_slice || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type))
808808
}
809809

810810
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> Option<FixedOffsetVar> {
@@ -1557,7 +1557,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
15571557
_ => arg,
15581558
};
15591559

1560-
if match_type(cx, ty, &paths::HASHMAP) || match_type(cx, ty, &paths::BTREEMAP) {
1560+
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) {
15611561
span_lint_and_then(
15621562
cx,
15631563
FOR_KV_MAP,
@@ -1959,9 +1959,9 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
19591959
is_iterable_array(ty, cx) ||
19601960
is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
19611961
match_type(cx, ty, &paths::LINKED_LIST) ||
1962-
match_type(cx, ty, &paths::HASHMAP) ||
1963-
match_type(cx, ty, &paths::HASHSET) ||
1964-
match_type(cx, ty, &paths::VEC_DEQUE) ||
1962+
is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) ||
1963+
is_type_diagnostic_item(cx, ty, sym!(hashset_type)) ||
1964+
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
19651965
match_type(cx, ty, &paths::BINARY_HEAP) ||
19661966
match_type(cx, ty, &paths::BTREEMAP) ||
19671967
match_type(cx, ty, &paths::BTREESET)
@@ -2468,9 +2468,9 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, '
24682468
then {
24692469
let ty = cx.tables.node_type(ty.hir_id);
24702470
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
2471-
match_type(cx, ty, &paths::VEC_DEQUE) ||
2471+
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
24722472
match_type(cx, ty, &paths::BTREEMAP) ||
2473-
match_type(cx, ty, &paths::HASHMAP) {
2473+
is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) {
24742474
if method.ident.name == sym!(len) {
24752475
let span = shorten_needless_collect_span(expr);
24762476
span_lint_and_sugg(

clippy_lints/src/methods/inefficient_to_string.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::INEFFICIENT_TO_STRING;
2-
use crate::utils::{match_def_path, paths, snippet_with_applicability, span_lint_and_then, walk_ptrs_ty_depth};
2+
use crate::utils::{match_def_path, is_type_diagnostic_item, paths, snippet_with_applicability, span_lint_and_then, walk_ptrs_ty_depth};
33
use if_chain::if_chain;
44
use rustc_errors::Applicability;
55
use rustc_hir as hir;
@@ -44,12 +44,18 @@ pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::E
4444
/// Returns whether `ty` specializes `ToString`.
4545
/// Currently, these are `str`, `String`, and `Cow<'_, str>`.
4646
fn specializes_tostring(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
47-
match ty.kind {
48-
ty::Str => true,
49-
ty::Adt(adt, substs) => {
50-
match_def_path(cx, adt.did, &paths::STRING)
51-
|| (match_def_path(cx, adt.did, &paths::COW) && substs.type_at(1).is_str())
52-
},
53-
_ => false,
47+
if let ty::Str = ty.kind {
48+
return true
49+
}
50+
51+
if is_type_diagnostic_item(cx, ty, sym!(string_type)) {
52+
return true
53+
}
54+
55+
if let ty::Adt(adt, substs) = ty.kind {
56+
match_def_path(cx, adt.did, &paths::COW) &&
57+
substs.type_at(1).is_str()
58+
} else {
59+
false
5460
}
5561
}

clippy_lints/src/methods/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ fn lint_expect_fun_call(
17561756
&& {
17571757
let arg_type = cx.tables.expr_ty(&call_args[0]);
17581758
let base_type = walk_ptrs_ty(arg_type);
1759-
base_type.kind == ty::Str || match_type(cx, base_type, &paths::STRING)
1759+
base_type.kind == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type))
17601760
}
17611761
{
17621762
&call_args[0]
@@ -1774,7 +1774,7 @@ fn lint_expect_fun_call(
17741774
// converted to string.
17751775
fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool {
17761776
let arg_ty = cx.tables.expr_ty(arg);
1777-
if match_type(cx, arg_ty, &paths::STRING) {
1777+
if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) {
17781778
return false;
17791779
}
17801780
if let ty::Ref(_, ty, ..) = arg_ty.kind {
@@ -2054,7 +2054,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi
20542054
let self_ty = walk_ptrs_ty(cx.tables.expr_ty(target));
20552055
let ref_str = if self_ty.kind == ty::Str {
20562056
""
2057-
} else if match_type(cx, self_ty, &paths::STRING) {
2057+
} else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) {
20582058
"&"
20592059
} else {
20602060
return;
@@ -2080,7 +2080,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi
20802080

20812081
fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
20822082
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0]));
2083-
if match_type(cx, obj_ty, &paths::STRING) {
2083+
if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) {
20842084
lint_string_extend(cx, expr, args);
20852085
}
20862086
}
@@ -2242,7 +2242,7 @@ fn lint_iter_nth<'a, 'tcx>(
22422242
"slice"
22432243
} else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vec_type)) {
22442244
"Vec"
2245-
} else if match_type(cx, cx.tables.expr_ty(&iter_args[0]), &paths::VEC_DEQUE) {
2245+
} else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vecdeque_type)) {
22462246
"VecDeque"
22472247
} else {
22482248
let nth_args = nth_and_iter_args[0];
@@ -2301,10 +2301,10 @@ fn lint_get_unwrap<'a, 'tcx>(
23012301
} else if is_type_diagnostic_item(cx, expr_ty, sym!(vec_type)) {
23022302
needs_ref = get_args_str.parse::<usize>().is_ok();
23032303
"Vec"
2304-
} else if match_type(cx, expr_ty, &paths::VEC_DEQUE) {
2304+
} else if is_type_diagnostic_item(cx, expr_ty, sym!(vecdeque_type)) {
23052305
needs_ref = get_args_str.parse::<usize>().is_ok();
23062306
"VecDeque"
2307-
} else if !is_mut && match_type(cx, expr_ty, &paths::HASHMAP) {
2307+
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym!(hashmap_type)) {
23082308
needs_ref = true;
23092309
"HashMap"
23102310
} else if !is_mut && match_type(cx, expr_ty, &paths::BTREEMAP) {
@@ -2510,7 +2510,7 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<
25102510
}
25112511

25122512
// lint if caller of `.map().flatten()` is an Option
2513-
if match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION) {
2513+
if is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)) {
25142514
let msg = "called `map(..).flatten()` on an `Option`. \
25152515
This is more succinctly expressed by calling `.and_then(..)`";
25162516
let self_snippet = snippet(cx, map_args[0].span, "..");
@@ -2678,7 +2678,7 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg
26782678
const NO_OP_MSG: &str = "using `Option.and_then(Some)`, which is a no-op";
26792679

26802680
let ty = cx.tables.expr_ty(&args[0]);
2681-
if !match_type(cx, ty, &paths::OPTION) {
2681+
if !is_type_diagnostic_item(cx, ty, sym!(option_type)) {
26822682
return;
26832683
}
26842684

@@ -3282,7 +3282,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
32823282
let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not);
32833283

32843284
let option_ty = cx.tables.expr_ty(&as_ref_args[0]);
3285-
if !match_type(cx, option_ty, &paths::OPTION) {
3285+
if !is_type_diagnostic_item(cx, option_ty, sym!(option_type)) {
32863286
return;
32873287
}
32883288

clippy_lints/src/mutex_atomic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This lint is **warn** by default
44
5-
use crate::utils::{match_type, paths, span_lint};
5+
use crate::utils::{is_type_diagnostic_item, span_lint};
66
use rustc_ast::ast;
77
use rustc_hir::Expr;
88
use rustc_lint::{LateContext, LateLintPass};
@@ -58,7 +58,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex {
5858
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
5959
let ty = cx.tables.expr_ty(expr);
6060
if let ty::Adt(_, subst) = ty.kind {
61-
if match_type(cx, ty, &paths::MUTEX) {
61+
if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) {
6262
let mutex_param = subst.type_at(0);
6363
if let Some(atomic_name) = get_atomic_name(mutex_param) {
6464
let msg = format!(

clippy_lints/src/needless_pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::ptr::get_spans;
22
use crate::utils::{
3-
get_trait_def_id, implements_trait, is_copy, is_self, is_type_diagnostic_item, match_type, multispan_sugg, paths,
3+
get_trait_def_id, implements_trait, is_copy, is_self, is_type_diagnostic_item, multispan_sugg, paths,
44
snippet, snippet_opt, span_lint_and_then,
55
};
66
use if_chain::if_chain;
@@ -253,7 +253,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
253253
}
254254
}
255255

256-
if match_type(cx, ty, &paths::STRING) {
256+
if is_type_diagnostic_item(cx, ty, sym!(string_type)) {
257257
if let Some(clone_spans) =
258258
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) {
259259
diag.span_suggestion(

clippy_lints/src/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_
197197
},
198198
);
199199
}
200-
} else if match_type(cx, ty, &paths::STRING) {
200+
} else if is_type_diagnostic_item(cx, ty, sym!(string_type)) {
201201
if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) {
202202
span_lint_and_then(
203203
cx,

clippy_lints/src/redundant_clone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
fn_has_unsatisfiable_preds, has_drop, is_copy, match_def_path, match_type, paths, snippet_opt, span_lint_hir,
2+
fn_has_unsatisfiable_preds, has_drop, is_copy, is_type_diagnostic_item, match_def_path, match_type, paths, snippet_opt, span_lint_hir,
33
span_lint_hir_and_then, walk_ptrs_ty_depth,
44
};
55
use if_chain::if_chain;
@@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
113113

114114
let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD)
115115
|| match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD)
116-
|| (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD) && match_type(cx, arg_ty, &paths::STRING));
116+
|| (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD) && is_type_diagnostic_item(cx, arg_ty, sym!(string_type)));
117117

118118
let from_deref = !from_borrow
119119
&& (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF)

clippy_lints/src/strings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::source_map::Spanned;
88
use if_chain::if_chain;
99

1010
use crate::utils::SpanlessEq;
11-
use crate::utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty};
11+
use crate::utils::{get_parent_expr, is_allowed, is_type_diagnostic_item, span_lint, span_lint_and_sugg, walk_ptrs_ty};
1212

1313
declare_clippy_lint! {
1414
/// **What it does:** Checks for string appends of the form `x = x + y` (without
@@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
126126
}
127127

128128
fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
129-
match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), &paths::STRING)
129+
is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), sym!(string_type))
130130
}
131131

132132
fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool {

clippy_lints/src/swap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::sugg::Sugg;
22
use crate::utils::{
3-
differing_macro_contexts, is_type_diagnostic_item, match_type, paths, snippet_with_applicability,
3+
differing_macro_contexts, is_type_diagnostic_item, snippet_with_applicability,
44
span_lint_and_then, walk_ptrs_ty, SpanlessEq,
55
};
66
use if_chain::if_chain;
@@ -199,7 +199,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a E
199199
if matches!(ty.kind, ty::Slice(_))
200200
|| matches!(ty.kind, ty::Array(_, _))
201201
|| is_type_diagnostic_item(cx, ty, sym!(vec_type))
202-
|| match_type(cx, ty, &paths::VEC_DEQUE)
202+
|| is_type_diagnostic_item(cx, ty, sym!(vecdeque_type))
203203
{
204204
return Slice::Swappable(lhs1, idx1, idx2);
205205
}

clippy_lints/src/types.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_typeck::hir_ty_to_ty;
2929
use crate::consts::{constant, Constant};
3030
use crate::utils::paths;
3131
use crate::utils::{
32-
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, last_path_segment, match_def_path,
32+
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, is_type_diagnostic_item, last_path_segment, match_def_path,
3333
match_path, method_chain_args, multispan_sugg, numeric_literal::NumericLiteral, qpath_res, same_tys, sext, snippet,
3434
snippet_opt, snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help,
3535
span_lint_and_sugg, span_lint_and_then, unsext,
@@ -2352,14 +2352,14 @@ impl<'tcx> ImplicitHasherType<'tcx> {
23522352

23532353
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
23542354

2355-
if match_path(path, &paths::HASHMAP) && params_len == 2 {
2355+
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) && params_len == 2 {
23562356
Some(ImplicitHasherType::HashMap(
23572357
hir_ty.span,
23582358
ty,
23592359
snippet(cx, params[0].span, "K"),
23602360
snippet(cx, params[1].span, "V"),
23612361
))
2362-
} else if match_path(path, &paths::HASHSET) && params_len == 1 {
2362+
} else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) && params_len == 1 {
23632363
Some(ImplicitHasherType::HashSet(
23642364
hir_ty.span,
23652365
ty,
@@ -2460,13 +2460,14 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
24602460
if_chain! {
24612461
if let ExprKind::Call(ref fun, ref args) = e.kind;
24622462
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind;
2463-
if let TyKind::Path(QPath::Resolved(None, ref ty_path)) = ty.kind;
24642463
then {
24652464
if !same_tys(self.cx, self.target.ty(), self.body.expr_ty(e)) {
24662465
return;
24672466
}
24682467

2469-
if match_path(ty_path, &paths::HASHMAP) {
2468+
let ty = hir_ty_to_ty(self.cx.tcx, ty);
2469+
2470+
if is_type_diagnostic_item(self.cx, ty, sym!(hashmap_type)) {
24702471
if method.ident.name == sym!(new) {
24712472
self.suggestions
24722473
.insert(e.span, "HashMap::default()".to_string());
@@ -2479,7 +2480,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
24792480
),
24802481
);
24812482
}
2482-
} else if match_path(ty_path, &paths::HASHSET) {
2483+
} else if is_type_diagnostic_item(self.cx, ty, sym!(hashset_type)) {
24832484
if method.ident.name == sym!(new) {
24842485
self.suggestions
24852486
.insert(e.span, "HashSet::default()".to_string());

clippy_lints/src/utils/paths.rs

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
6161
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];
6262
pub const MEM_MAYBEUNINIT_UNINIT: [&str; 5] = ["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"];
6363
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];
64-
pub const MUTEX: [&str; 4] = ["std", "sync", "mutex", "Mutex"];
6564
pub const MUTEX_GUARD: [&str; 4] = ["std", "sync", "mutex", "MutexGuard"];
6665
pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"];
6766
pub const OPS_MODULE: [&str; 2] = ["core", "ops"];
@@ -120,7 +119,6 @@ pub const STDOUT: [&str; 4] = ["std", "io", "stdio", "stdout"];
120119
pub const STD_CONVERT_IDENTITY: [&str; 3] = ["std", "convert", "identity"];
121120
pub const STD_MEM_TRANSMUTE: [&str; 3] = ["std", "mem", "transmute"];
122121
pub const STD_PTR_NULL: [&str; 3] = ["std", "ptr", "null"];
123-
pub const STRING: [&str; 3] = ["alloc", "string", "String"];
124122
pub const STRING_AS_MUT_STR: [&str; 4] = ["alloc", "string", "String", "as_mut_str"];
125123
pub const STRING_AS_STR: [&str; 4] = ["alloc", "string", "String", "as_str"];
126124
pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"];

0 commit comments

Comments
 (0)