Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #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 representation
- Loading branch information