diff options
| author | inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-07-30 23:50:57 -0700 |
|---|---|---|
| committer | inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-08-28 00:16:34 -0700 |
| commit | 8c62fa057527fc07afabb201bb31428409ef4d8a (patch) | |
| tree | b406fd584e223518dc4588c93d7b814a1bbe8489 /compiler/rustc_ast_pretty/src/pprust | |
| parent | ac50a53359328a5d7f2f558833e63d59d372e4f7 (diff) | |
| download | rust-8c62fa057527fc07afabb201bb31428409ef4d8a.tar.gz rust-8c62fa057527fc07afabb201bb31428409ef4d8a.zip | |
Treat macros as HIR items
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index b09c668273a..f729973ddc6 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -578,6 +578,33 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere } } + fn print_mac_def( + &mut self, + macro_def: &ast::MacroDef, + ident: &Ident, + sp: &Span, + print_visibility: impl FnOnce(&mut Self), + ) { + let (kw, has_bang) = if macro_def.macro_rules { + ("macro_rules", true) + } else { + print_visibility(self); + ("macro", false) + }; + self.print_mac_common( + Some(MacHeader::Keyword(kw)), + has_bang, + Some(*ident), + macro_def.body.delim(), + ¯o_def.body.inner_tokens(), + true, + *sp, + ); + if macro_def.body.need_semicolon() { + self.word(";"); + } + } + fn print_path(&mut self, path: &ast::Path, colons_before_params: bool, depth: usize) { self.maybe_print_comment(path.span.lo()); @@ -1305,24 +1332,9 @@ impl<'a> State<'a> { } } ast::ItemKind::MacroDef(ref macro_def) => { - let (kw, has_bang) = if macro_def.macro_rules { - ("macro_rules", true) - } else { - self.print_visibility(&item.vis); - ("macro", false) - }; - self.print_mac_common( - Some(MacHeader::Keyword(kw)), - has_bang, - Some(item.ident), - macro_def.body.delim(), - ¯o_def.body.inner_tokens(), - true, - item.span, - ); - if macro_def.body.need_semicolon() { - self.word(";"); - } + self.print_mac_def(macro_def, &item.ident, &item.span, |state| { + state.print_visibility(&item.vis) + }); } } self.ann.post(self, AnnNode::Item(item)) |
