Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere

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)),
Expand Down Expand Up @@ -655,6 +662,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.word(token_str);
}
}
match item.unsafety {
ast::Safety::Unsafe(_) => self.pclose(),
ast::Safety::Default | ast::Safety::Safe(_) => {}
}
self.end();
}

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/unpretty/unsafe-attr.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/ui/unpretty/unsafe-attr.stdout
Original file line number Diff line number Diff line change
@@ -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