Skip to content

Commit ae0576a

Browse files
committed
Auto merge of #5509 - phansch:more-diagnostic-items2, r=<try>
Use more diagnostic items In particular for: * `VecDeque` * `String` * `Mutex` * `HashMap` * `HashSet` cc rust-lang/rust#71414 #5393 --- changelog: none
2 parents b7c802b + ed3d487 commit ae0576a

15 files changed

+68
-60
lines changed

Diff for: 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 {

Diff for: clippy_lints/src/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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,
4-
walk_ptrs_ty,
3+
is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet,
4+
span_lint_and_then, walk_ptrs_ty,
55
};
66
use if_chain::if_chain;
77
use rustc_ast::ast::LitKind;
@@ -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 {

Diff for: 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 {

Diff for: clippy_lints/src/inherent_to_string.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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,
8-
walk_ptrs_ty,
7+
get_trait_def_id, implements_trait, is_type_diagnostic_item, paths, return_ty, span_lint_and_help,
8+
trait_ref_of_method, walk_ptrs_ty,
99
};
1010

1111
declare_clippy_lint! {
@@ -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();

Diff for: clippy_lints/src/loops.rs

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

819-
is_slice || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || match_type(cx, ty, &paths::VEC_DEQUE)
819+
is_slice || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type))
820820
}
821821

822822
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> Option<FixedOffsetVar> {
@@ -1569,7 +1569,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
15691569
_ => arg,
15701570
};
15711571

1572-
if match_type(cx, ty, &paths::HASHMAP) || match_type(cx, ty, &paths::BTREEMAP) {
1572+
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) {
15731573
span_lint_and_then(
15741574
cx,
15751575
FOR_KV_MAP,
@@ -1971,9 +1971,9 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
19711971
is_iterable_array(ty, cx) ||
19721972
is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
19731973
match_type(cx, ty, &paths::LINKED_LIST) ||
1974-
match_type(cx, ty, &paths::HASHMAP) ||
1975-
match_type(cx, ty, &paths::HASHSET) ||
1976-
match_type(cx, ty, &paths::VEC_DEQUE) ||
1974+
is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) ||
1975+
is_type_diagnostic_item(cx, ty, sym!(hashset_type)) ||
1976+
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
19771977
match_type(cx, ty, &paths::BINARY_HEAP) ||
19781978
match_type(cx, ty, &paths::BTREEMAP) ||
19791979
match_type(cx, ty, &paths::BTREESET)
@@ -2480,9 +2480,9 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, '
24802480
then {
24812481
let ty = cx.tables.node_type(ty.hir_id);
24822482
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
2483-
match_type(cx, ty, &paths::VEC_DEQUE) ||
2483+
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
24842484
match_type(cx, ty, &paths::BTREEMAP) ||
2485-
match_type(cx, ty, &paths::HASHMAP) {
2485+
is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) {
24862486
if method.ident.name == sym!(len) {
24872487
let span = shorten_needless_collect_span(expr);
24882488
span_lint_and_sugg(

Diff for: clippy_lints/src/methods/inefficient_to_string.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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::{
3+
is_type_diagnostic_item, match_def_path, paths, snippet_with_applicability, span_lint_and_then, walk_ptrs_ty_depth,
4+
};
35
use if_chain::if_chain;
46
use rustc_errors::Applicability;
57
use rustc_hir as hir;
@@ -44,12 +46,17 @@ pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::E
4446
/// Returns whether `ty` specializes `ToString`.
4547
/// Currently, these are `str`, `String`, and `Cow<'_, str>`.
4648
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,
49+
if let ty::Str = ty.kind {
50+
return true;
51+
}
52+
53+
if is_type_diagnostic_item(cx, ty, sym!(string_type)) {
54+
return true;
55+
}
56+
57+
if let ty::Adt(adt, substs) = ty.kind {
58+
match_def_path(cx, adt.did, &paths::COW) && substs.type_at(1).is_str()
59+
} else {
60+
false
5461
}
5562
}

Diff for: 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

Diff for: 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!(

Diff for: clippy_lints/src/needless_pass_by_value.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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,
4-
snippet, snippet_opt, span_lint_and_then,
3+
get_trait_def_id, implements_trait, is_copy, is_self, is_type_diagnostic_item, multispan_sugg, paths, snippet,
4+
snippet_opt, span_lint_and_then,
55
};
66
use if_chain::if_chain;
77
use rustc_ast::ast::Attribute;
@@ -254,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
254254
}
255255
}
256256

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

Diff for: 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,

Diff for: clippy_lints/src/redundant_clone.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
2-
fn_has_unsatisfiable_preds, has_drop, is_copy, match_def_path, match_type, paths, snippet_opt, span_lint_hir,
3-
span_lint_hir_and_then, walk_ptrs_ty_depth,
2+
fn_has_unsatisfiable_preds, has_drop, is_copy, is_type_diagnostic_item, match_def_path, match_type, paths,
3+
snippet_opt, span_lint_hir, span_lint_hir_and_then, walk_ptrs_ty_depth,
44
};
55
use if_chain::if_chain;
66
use rustc_data_structures::{fx::FxHashMap, transitive_relation::TransitiveRelation};
@@ -113,7 +113,8 @@ 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)
117+
&& is_type_diagnostic_item(cx, arg_ty, sym!(string_type)));
117118

118119
let from_deref = !from_borrow
119120
&& (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF)

Diff for: 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 {

Diff for: clippy_lints/src/swap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::sugg::Sugg;
22
use crate::utils::{
3-
differing_macro_contexts, is_type_diagnostic_item, match_type, paths, snippet_with_applicability,
4-
span_lint_and_then, walk_ptrs_ty, SpanlessEq,
3+
differing_macro_contexts, is_type_diagnostic_item, snippet_with_applicability, span_lint_and_then, walk_ptrs_ty,
4+
SpanlessEq,
55
};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
@@ -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
}

Diff for: clippy_lints/src/types.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ 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,
33-
match_path, method_chain_args, multispan_sugg, numeric_literal::NumericLiteral, qpath_res, same_tys, sext, snippet,
34-
snippet_opt, snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help,
35-
span_lint_and_sugg, span_lint_and_then, unsext,
32+
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, is_type_diagnostic_item,
33+
last_path_segment, match_def_path, match_path, method_chain_args, multispan_sugg, numeric_literal::NumericLiteral,
34+
qpath_res, same_tys, sext, snippet, snippet_opt, snippet_with_applicability, snippet_with_macro_callsite,
35+
span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, unsext,
3636
};
3737

3838
declare_clippy_lint! {
@@ -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,15 @@ 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;
2463+
if let TyKind::Path(QPath::Resolved(None, _)) = ty.kind;
24642464
then {
24652465
if !same_tys(self.cx, self.target.ty(), self.body.expr_ty(e)) {
24662466
return;
24672467
}
24682468

2469-
if match_path(ty_path, &paths::HASHMAP) {
2469+
let ty = hir_ty_to_ty(self.cx.tcx, ty);
2470+
2471+
if is_type_diagnostic_item(self.cx, ty, sym!(hashmap_type)) {
24702472
if method.ident.name == sym!(new) {
24712473
self.suggestions
24722474
.insert(e.span, "HashMap::default()".to_string());
@@ -2479,7 +2481,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
24792481
),
24802482
);
24812483
}
2482-
} else if match_path(ty_path, &paths::HASHSET) {
2484+
} else if is_type_diagnostic_item(self.cx, ty, sym!(hashset_type)) {
24832485
if method.ident.name == sym!(new) {
24842486
self.suggestions
24852487
.insert(e.span, "HashSet::default()".to_string());

0 commit comments

Comments
 (0)