|
| 1 | +use clippy_utils::path_res; |
| 2 | +use rustc_hir::def::Res; |
1 | 3 | use rustc_hir::{Impl, Item, ItemKind};
|
2 | 4 | use rustc_lint::{LateContext, LateLintPass};
|
3 | 5 | use rustc_session::declare_lint_pass;
|
@@ -194,21 +196,25 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
|
194 | 196 | fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
195 | 197 | if let ItemKind::Impl(Impl {
|
196 | 198 | of_trait: Some(of_trait),
|
| 199 | + self_ty, |
197 | 200 | ..
|
198 | 201 | }) = item.kind
|
| 202 | + && let Res::Def(_, def_id) = path_res(cx, self_ty) |
| 203 | + && let Some(local_def_id) = def_id.as_local() |
199 | 204 | {
|
| 205 | + let adt_hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); |
200 | 206 | let trait_ref = &of_trait.trait_ref;
|
201 | 207 | let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
202 | 208 | let is_automatically_derived = cx.tcx.is_automatically_derived(item.owner_id.to_def_id());
|
203 | 209 |
|
204 |
| - derived_hash_with_manual_eq::check(cx, item.span, trait_ref, ty, is_automatically_derived); |
205 |
| - derive_ord_xor_partial_ord::check(cx, item.span, trait_ref, ty, is_automatically_derived); |
| 210 | + derived_hash_with_manual_eq::check(cx, item.span, trait_ref, ty, adt_hir_id, is_automatically_derived); |
| 211 | + derive_ord_xor_partial_ord::check(cx, item.span, trait_ref, ty, adt_hir_id, is_automatically_derived); |
206 | 212 |
|
207 | 213 | if is_automatically_derived {
|
208 |
| - unsafe_derive_deserialize::check(cx, item, trait_ref, ty); |
209 |
| - derive_partial_eq_without_eq::check(cx, item.span, trait_ref, ty); |
| 214 | + unsafe_derive_deserialize::check(cx, item, trait_ref, ty, adt_hir_id); |
| 215 | + derive_partial_eq_without_eq::check(cx, item.span, trait_ref, ty, adt_hir_id); |
210 | 216 | } else {
|
211 |
| - expl_impl_clone_on_copy::check(cx, item, trait_ref, ty); |
| 217 | + expl_impl_clone_on_copy::check(cx, item, trait_ref, ty, adt_hir_id); |
212 | 218 | }
|
213 | 219 | }
|
214 | 220 | }
|
|
0 commit comments