Rollup merge of #132088 - compiler-errors:extern-static, r=jieyouxu

Print safety correctly in extern static items

Fixes #132080

r? spastorino or anyone really
This commit is contained in:
Stuart Cook 2024-10-24 14:19:58 +11:00 committed by GitHub
commit 7e2bbc30b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -38,7 +38,6 @@ fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
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),
@ -46,6 +45,7 @@ fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
ty,
expr.as_deref(),
vis,
*safety,
ast::Defaultness::Final,
)
}
@ -84,10 +84,12 @@ fn print_item_const(
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",
@ -181,6 +183,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
ty,
body.as_deref(),
&item.vis,
ast::Safety::Default,
ast::Defaultness::Final,
);
}
@ -192,6 +195,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
ty,
expr.as_deref(),
&item.vis,
ast::Safety::Default,
*defaultness,
);
}
@ -549,6 +553,7 @@ fn print_assoc_item(&mut self, item: &ast::AssocItem) {
ty,
expr.as_deref(),
vis,
ast::Safety::Default,
*defaultness,
);
}

View File

@ -0,0 +1,6 @@
//@ compile-flags: -Zunpretty=normal
//@ check-pass
unsafe extern "C" {
pub unsafe static STATIC: ();
}

View File

@ -0,0 +1,6 @@
//@ compile-flags: -Zunpretty=normal
//@ check-pass
unsafe extern "C" {
pub unsafe static STATIC: ();
}