Rollup merge of #132180 - Urgau:ast_pretty-unsafe-attr, r=compiler-errors
Print unsafety of attribute in AST pretty print This PR fixes the AST pretty print, which was missing the unsafety for unsafe attributes. Related to https://github.com/rust-lang/rust/pull/131558#discussion_r1807736204
This commit is contained in:
commit
50e78b8b3c
@ -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();
|
||||
}
|
||||
|
||||
|
11
tests/ui/unpretty/unsafe-attr.rs
Normal file
11
tests/ui/unpretty/unsafe-attr.rs
Normal file
@ -0,0 +1,11 @@
|
||||
//@ compile-flags: -Zunpretty=normal
|
||||
//@ check-pass
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn foo() {}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn bar() {}
|
||||
|
||||
#[cfg_attr(FALSE, unsafe(no_mangle))]
|
||||
extern "C" fn zoo() {}
|
11
tests/ui/unpretty/unsafe-attr.stdout
Normal file
11
tests/ui/unpretty/unsafe-attr.stdout
Normal file
@ -0,0 +1,11 @@
|
||||
//@ compile-flags: -Zunpretty=normal
|
||||
//@ check-pass
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn foo() {}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn bar() {}
|
||||
|
||||
#[cfg_attr(FALSE, unsafe(no_mangle))]
|
||||
extern "C" fn zoo() {}
|
Loading…
Reference in New Issue
Block a user