diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-03-14 20:34:43 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-03-17 15:58:25 +0300 |
| commit | 9dd4e4cad1a683d2319471c4025aed41341110c3 (patch) | |
| tree | 7bcc1a86f7c9a3826299c14359936558b05bd71c /compiler/rustc_ast_pretty/src/pprust/state.rs | |
| parent | 9bad8ac498985707f29b0bdc0293cc0457a3ab38 (diff) | |
| download | rust-9dd4e4cad1a683d2319471c4025aed41341110c3.tar.gz rust-9dd4e4cad1a683d2319471c4025aed41341110c3.zip | |
expand: Leave traces when expanding `cfg_attr` attributes
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state.rs')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index a8eaff7346b..cdb18179449 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -578,11 +578,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere let mut printed = false; for attr in attrs { if attr.style == kind { - self.print_attribute_inline(attr, is_inline); - if is_inline { - self.nbsp(); + if self.print_attribute_inline(attr, is_inline) { + if is_inline { + self.nbsp(); + } + printed = true; } - printed = true; } } if printed && trailing_hardbreak && !is_inline { @@ -591,7 +592,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere printed } - fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) { + fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) -> bool { + if attr.has_name(sym::cfg_attr_trace) { + // It's not a valid identifier, so avoid printing it + // to keep the printed code reasonably parse-able. + return false; + } if !is_inline { self.hardbreak_if_not_bol(); } @@ -610,6 +616,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere self.hardbreak() } } + true } fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) { @@ -2047,7 +2054,7 @@ impl<'a> State<'a> { } fn print_attribute(&mut self, attr: &ast::Attribute) { - self.print_attribute_inline(attr, false) + self.print_attribute_inline(attr, false); } fn print_meta_list_item(&mut self, item: &ast::MetaItemInner) { |
