Commit 95de4dc
committed
Auto merge of rust-lang#8701 - xFrednet:0000-clippy-print-hir-attr, r=flip1995
Rework `#[clippy::dump]` attribute for debugging
Hey `@rust-lang/clippy,` this adds a new `#[clippy::print_hir]` attribute that prints the node to the console using `{:#?}`. Personally, I use print debugging quite a lot while working on Clippy, and this is a simple shortcut that also works in the playground (Once this has been synced). The question is now, if we want to have this attribute. Are there any concerns? I think it's similar to our `#[clippy::author]` attribute.
I haven't added a test, as the `.stdout` file would require updates with every HIR change inside rustc. Here are some examples, for the current implementation
<details>
<summary>`do_something(&map);`</summary>
```rs
Expr {
hir_id: HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 21,
},
kind: Call(
Expr {
hir_id: HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 17,
},
kind: Path(
Resolved(
None,
Path {
span: tests/ui/aaa.rs:23:5: 23:17 (#0),
res: Def(
Fn,
DefId(0:6 ~ aaa[995b]::do_something),
),
segments: [
PathSegment {
ident: do_something#0,
hir_id: Some(
HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 16,
},
),
res: Some(
Err,
),
args: None,
infer_args: true,
},
],
},
),
),
span: tests/ui/aaa.rs:23:5: 23:17 (#0),
},
[
Expr {
hir_id: HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 20,
},
kind: AddrOf(
Ref,
Not,
Expr {
hir_id: HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 19,
},
kind: Path(
Resolved(
None,
Path {
span: tests/ui/aaa.rs:23:19: 23:22 (#0),
res: Local(
HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 15,
},
),
segments: [
PathSegment {
ident: map#0,
hir_id: Some(
HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 18,
},
),
res: Some(
Local(
HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 15,
},
),
),
args: None,
infer_args: true,
},
],
},
),
),
span: tests/ui/aaa.rs:23:19: 23:22 (#0),
},
),
span: tests/ui/aaa.rs:23:18: 23:22 (#0),
},
],
),
span: tests/ui/aaa.rs:23:5: 23:23 (#0),
}
```
</details>
<details>
<summary>`use std::collections::HashMap;`</summary>
```rs
Item {
ident: HashMap#0,
def_id: DefId(0:5 ~ aaa[995b]::{misc#1}),
kind: Use(
Path {
span: tests/ui/aaa.rs:8:5: 8:30 (#0),
res: Def(
Struct,
DefId(1:1294 ~ std[928b]::collections::hash::map::HashMap),
),
segments: [
PathSegment {
ident: std#0,
hir_id: Some(
HirId {
owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
local_id: 1,
},
),
res: Some(
Def(
Mod,
DefId(1:0 ~ std[928b]),
),
),
args: None,
infer_args: false,
},
PathSegment {
ident: collections#0,
hir_id: Some(
HirId {
owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
local_id: 2,
},
),
res: Some(
Def(
Mod,
DefId(1:1193 ~ std[928b]::collections),
),
),
args: None,
infer_args: false,
},
PathSegment {
ident: HashMap#0,
hir_id: Some(
HirId {
owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
local_id: 3,
},
),
res: Some(
Err,
),
args: None,
infer_args: false,
},
],
},
Single,
),
vis: Spanned {
node: Inherited,
span: tests/ui/aaa.rs:8:1: 8:1 (#0),
},
span: tests/ui/aaa.rs:8:1: 8:31 (#0),
}
```
</details>
<details>
<summary>`"100"`</summary>
```rs
Expr {
hir_id: HirId {
owner: DefId(0:7 ~ aaa[995b]::main),
local_id: 27,
},
kind: Lit(
Spanned {
node: Str(
"100",
Cooked,
),
span: tests/ui/aaa.rs:28:9: 28:14 (#0),
},
),
span: tests/ui/aaa.rs:28:9: 28:14 (#0),
}
```
</details>
---
changelog: Added `[clippy::print_hir]` to inspect rustc's internal representationFile tree
6 files changed
+72
-558
lines changed- clippy_lints/src
- utils
- internal_lints
- doc
6 files changed
+72
-558
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
506 | 505 | | |
507 | 506 | | |
508 | 507 | | |
| |||
514 | 513 | | |
515 | 514 | | |
516 | 515 | | |
| 516 | + | |
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
0 commit comments