|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then;
|
2 | 2 | use clippy_utils::is_lint_allowed;
|
3 | 3 | use clippy_utils::macros::span_is_local;
|
4 |
| -use rustc_hir::def_id::DefIdMap; |
| 4 | +use rustc_hir::def_id::DefIdSet; |
5 | 5 | use rustc_hir::{Impl, Item, ItemKind};
|
6 | 6 | use rustc_lint::{LateContext, LateLintPass};
|
7 |
| -use rustc_middle::ty::AssocItem; |
8 | 7 | use rustc_session::declare_lint_pass;
|
9 | 8 |
|
10 | 9 | declare_clippy_lint! {
|
@@ -68,33 +67,26 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
|
68 | 67 | }) = item.kind
|
69 | 68 | && let Some(trait_id) = trait_ref.trait_def_id()
|
70 | 69 | {
|
71 |
| - let mut provided: DefIdMap<&AssocItem> = cx |
72 |
| - .tcx |
73 |
| - .provided_trait_methods(trait_id) |
74 |
| - .map(|assoc| (assoc.def_id, assoc)) |
| 70 | + let trait_item_ids: DefIdSet = items |
| 71 | + .iter() |
| 72 | + .filter_map(|impl_item| impl_item.trait_item_def_id) |
75 | 73 | .collect();
|
76 | 74 |
|
77 |
| - for impl_item in *items { |
78 |
| - if let Some(def_id) = impl_item.trait_item_def_id { |
79 |
| - provided.remove(&def_id); |
80 |
| - } |
| 75 | + for assoc in cx |
| 76 | + .tcx |
| 77 | + .provided_trait_methods(trait_id) |
| 78 | + .filter(|assoc| !trait_item_ids.contains(&assoc.def_id)) |
| 79 | + { |
| 80 | + span_lint_and_then( |
| 81 | + cx, |
| 82 | + MISSING_TRAIT_METHODS, |
| 83 | + cx.tcx.def_span(item.owner_id), |
| 84 | + format!("missing trait method provided by default: `{}`", assoc.name), |
| 85 | + |diag| { |
| 86 | + diag.span_help(cx.tcx.def_span(assoc.def_id), "implement the method"); |
| 87 | + }, |
| 88 | + ); |
81 | 89 | }
|
82 |
| - |
83 |
| - cx.tcx.with_stable_hashing_context(|hcx| { |
84 |
| - for assoc in provided.values_sorted(&hcx, true) { |
85 |
| - let source_map = cx.tcx.sess.source_map(); |
86 |
| - span_lint_and_then( |
87 |
| - cx, |
88 |
| - MISSING_TRAIT_METHODS, |
89 |
| - source_map.guess_head_span(item.span), |
90 |
| - format!("missing trait method provided by default: `{}`", assoc.name), |
91 |
| - |diag| { |
92 |
| - let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id)); |
93 |
| - diag.span_help(definition_span, "implement the method"); |
94 |
| - }, |
95 |
| - ); |
96 |
| - } |
97 |
| - }); |
98 | 90 | }
|
99 | 91 | }
|
100 | 92 | }
|
0 commit comments