about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-09 13:22:00 +0000
committerbors <bors@rust-lang.org>2023-02-09 13:22:00 +0000
commit5adeebf92fd5a639d2cb51c7374fc212e5de568f (patch)
tree4dbc8ac2d9f67e50dd88c60e719814f6065c0f01
parentfd2d8beaf8d22caedb84edd4402191e7861117af (diff)
parentc642cfe3bf245ffe34f6e994f0b359b267be5e3d (diff)
downloadrust-5adeebf92fd5a639d2cb51c7374fc212e5de568f.tar.gz
rust-5adeebf92fd5a639d2cb51c7374fc212e5de568f.zip
Auto merge of #10292 - xFrednet:0000-support-trait-item-in-dump, r=flip1995
Make `[clippy::dump]` support trait items

Roses are red,
violets are blue,
trait items are rare,
`[clippy::dump]` is too

---

Let's just ignore the horrible poem... anyways. While working on Marker I noticed, that `[clippy::dump]` doesn't work on trait item (See [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e2d9791ffa2872e7c09a9dfbd470350c)). This simply adds support for that. `[clippy::dump]` doesn't have UI tests, to make it more resistant to changes in the AST. I tested it locally and the dump works after these changes.

---

changelog: none
-rw-r--r--clippy_lints/src/utils/dump_hir.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/clippy_lints/src/utils/dump_hir.rs b/clippy_lints/src/utils/dump_hir.rs
index 01efc527a8c..092041aecf2 100644
--- a/clippy_lints/src/utils/dump_hir.rs
+++ b/clippy_lints/src/utils/dump_hir.rs
@@ -1,4 +1,5 @@
 use clippy_utils::get_attr;
+use hir::TraitItem;
 use rustc_hir as hir;
 use rustc_lint::{LateContext, LateLintPass, LintContext};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -47,6 +48,18 @@ impl<'tcx> LateLintPass<'tcx> for DumpHir {
             println!("{stmt:#?}");
         }
     }
+
+    fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {
+        if has_attr(cx, item.hir_id()) {
+            println!("{item:#?}");
+        }
+    }
+
+    fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &hir::ImplItem<'_>) {
+        if has_attr(cx, item.hir_id()) {
+            println!("{item:#?}");
+        }
+    }
 }
 
 fn has_attr(cx: &LateContext<'_>, hir_id: hir::HirId) -> bool {