Skip to content

Commit

Permalink
Rollup merge of #132088 - compiler-errors:extern-static, r=jieyouxu
Browse files Browse the repository at this point in the history
Print safety correctly in extern static items

Fixes #132080

r? spastorino or anyone really
  • Loading branch information
Zalathar authored Oct 24, 2024
2 parents 006a142 + 4e1b3ab commit 7e2bbc3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ impl<'a> State<'a> {
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
}
ast::ForeignItemKind::Static(box ast::StaticItem { ty, mutability, expr, safety }) => {
self.print_safety(*safety);
self.print_item_const(
ident,
Some(*mutability),
&ast::Generics::default(),
ty,
expr.as_deref(),
vis,
*safety,
ast::Defaultness::Final,
)
}
Expand Down Expand Up @@ -84,10 +84,12 @@ impl<'a> State<'a> {
ty: &ast::Ty,
body: Option<&ast::Expr>,
vis: &ast::Visibility,
safety: ast::Safety,
defaultness: ast::Defaultness,
) {
self.head("");
self.print_visibility(vis);
self.print_safety(safety);
self.print_defaultness(defaultness);
let leading = match mutbl {
None => "const",
Expand Down Expand Up @@ -181,6 +183,7 @@ impl<'a> State<'a> {
ty,
body.as_deref(),
&item.vis,
ast::Safety::Default,
ast::Defaultness::Final,
);
}
Expand All @@ -192,6 +195,7 @@ impl<'a> State<'a> {
ty,
expr.as_deref(),
&item.vis,
ast::Safety::Default,
*defaultness,
);
}
Expand Down Expand Up @@ -549,6 +553,7 @@ impl<'a> State<'a> {
ty,
expr.as_deref(),
vis,
ast::Safety::Default,
*defaultness,
);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/unpretty/extern-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ compile-flags: -Zunpretty=normal
//@ check-pass

unsafe extern "C" {
pub unsafe static STATIC: ();
}
6 changes: 6 additions & 0 deletions tests/ui/unpretty/extern-static.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ compile-flags: -Zunpretty=normal
//@ check-pass

unsafe extern "C" {
pub unsafe static STATIC: ();
}

0 comments on commit 7e2bbc3

Please sign in to comment.