Skip to content

Commit

Permalink
Print unsafety of attribute in AST unpretty
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Oct 26, 2024
1 parent f249fdd commit f5b6f93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion tests/ui/unpretty/unsafe-attr.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down

0 comments on commit f5b6f93

Please sign in to comment.