Skip to content

Commit

Permalink
Auto merge of #10292 - xFrednet:0000-support-trait-item-in-dump, r=fl…
Browse files Browse the repository at this point in the history
…ip1995

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
  • Loading branch information
bors committed Feb 9, 2023
2 parents fd2d8be + c642cfe commit 5adeebf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clippy_lints/src/utils/dump_hir.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5adeebf

Please sign in to comment.