|
1 | 1 | use clippy_utils::{diagnostics::span_lint_and_sugg, ty::implements_trait}; |
2 | 2 | use rustc_errors::Applicability; |
3 | | -use rustc_hir::{def_id::LocalDefId, FnDecl, FnRetTy, Item, ItemKind, TraitItem, TraitItemKind}; |
| 3 | +use rustc_hir::{def_id::LocalDefId, FnDecl, FnRetTy, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind}; |
4 | 4 | use rustc_hir_analysis::hir_ty_to_ty; |
5 | 5 | use rustc_lint::{LateContext, LateLintPass}; |
6 | 6 | use rustc_session::{declare_tool_lint, impl_lint_pass}; |
@@ -87,6 +87,19 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns { |
87 | 87 | self.check_fn_decl(cx, signature.decl, item.owner_id.def_id); |
88 | 88 | } |
89 | 89 |
|
| 90 | + fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::ImplItem<'_>) { |
| 91 | + // Ignore implementations of traits, because the lint should be on the |
| 92 | + // trait, not on the implmentation of it. |
| 93 | + let Node::Item(parent) = cx.tcx.hir().get_parent(item.hir_id()) else { return }; |
| 94 | + let ItemKind::Impl(parent) = parent.kind else { return }; |
| 95 | + if parent.of_trait.is_some() { |
| 96 | + return; |
| 97 | + } |
| 98 | + |
| 99 | + let ImplItemKind::Fn(signature, ..) = &item.kind else { return }; |
| 100 | + self.check_fn_decl(cx, signature.decl, item.owner_id.def_id); |
| 101 | + } |
| 102 | + |
90 | 103 | fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { |
91 | 104 | let ItemKind::Fn(signature, ..) = &item.kind else { return }; |
92 | 105 | self.check_fn_decl(cx, signature.decl, item.owner_id.def_id); |
|
0 commit comments