From f5b6f938cec70d7b6ef3681217ad4c1d84e597e0 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 26 Oct 2024 13:33:36 +0200 Subject: [PATCH] Print unsafety of attribute in AST unpretty --- compiler/rustc_ast_pretty/src/pprust/state.rs | 11 +++++++++++ tests/ui/unpretty/unsafe-attr.stdout | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 2cdec2138ad..1e18f0779f0 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -627,6 +627,13 @@ fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) { fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) { self.ibox(0); + match item.unsafety { + ast::Safety::Unsafe(_) => { + self.word("unsafe"); + self.popen(); + } + ast::Safety::Default | ast::Safety::Safe(_) => {} + } match &item.args { AttrArgs::Delimited(DelimArgs { dspan: _, delim, tokens }) => self.print_mac_common( Some(MacHeader::Path(&item.path)), @@ -655,6 +662,10 @@ fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) { self.word(token_str); } } + match item.unsafety { + ast::Safety::Unsafe(_) => self.pclose(), + ast::Safety::Default | ast::Safety::Safe(_) => {} + } self.end(); } diff --git a/tests/ui/unpretty/unsafe-attr.stdout b/tests/ui/unpretty/unsafe-attr.stdout index 5d199337524..8734ea86b6d 100644 --- a/tests/ui/unpretty/unsafe-attr.stdout +++ b/tests/ui/unpretty/unsafe-attr.stdout @@ -4,7 +4,7 @@ #[no_mangle] extern "C" fn foo() {} -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn bar() {} #[cfg_attr(FALSE, unsafe(no_mangle))]