diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2024-10-24 14:19:58 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-24 14:19:58 +1100 |
| commit | 7e2bbc30b3eaa6068f78641d86be8173369bf8af (patch) | |
| tree | e7b52f5c833b25713898105f9294fb482a27c791 | |
| parent | 006a14230fee284d732c547eeee9816a5460dfb1 (diff) | |
| parent | 4e1b3ab0e7965b8cce016f1ca01cd2df37e11635 (diff) | |
| download | rust-7e2bbc30b3eaa6068f78641d86be8173369bf8af.tar.gz rust-7e2bbc30b3eaa6068f78641d86be8173369bf8af.zip | |
Rollup merge of #132088 - compiler-errors:extern-static, r=jieyouxu
Print safety correctly in extern static items Fixes #132080 r? spastorino or anyone really
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/item.rs | 7 | ||||
| -rw-r--r-- | tests/ui/unpretty/extern-static.rs | 6 | ||||
| -rw-r--r-- | tests/ui/unpretty/extern-static.stdout | 6 |
3 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 8217b6df5b4..8279c66836c 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -38,7 +38,6 @@ 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), @@ -46,6 +45,7 @@ impl<'a> State<'a> { ty, expr.as_deref(), vis, + *safety, ast::Defaultness::Final, ) } @@ -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", @@ -181,6 +183,7 @@ impl<'a> State<'a> { ty, body.as_deref(), &item.vis, + ast::Safety::Default, ast::Defaultness::Final, ); } @@ -192,6 +195,7 @@ impl<'a> State<'a> { ty, expr.as_deref(), &item.vis, + ast::Safety::Default, *defaultness, ); } @@ -549,6 +553,7 @@ impl<'a> State<'a> { ty, expr.as_deref(), vis, + ast::Safety::Default, *defaultness, ); } diff --git a/tests/ui/unpretty/extern-static.rs b/tests/ui/unpretty/extern-static.rs new file mode 100644 index 00000000000..fbd605b12ca --- /dev/null +++ b/tests/ui/unpretty/extern-static.rs @@ -0,0 +1,6 @@ +//@ compile-flags: -Zunpretty=normal +//@ check-pass + +unsafe extern "C" { + pub unsafe static STATIC: (); +} diff --git a/tests/ui/unpretty/extern-static.stdout b/tests/ui/unpretty/extern-static.stdout new file mode 100644 index 00000000000..fbd605b12ca --- /dev/null +++ b/tests/ui/unpretty/extern-static.stdout @@ -0,0 +1,6 @@ +//@ compile-flags: -Zunpretty=normal +//@ check-pass + +unsafe extern "C" { + pub unsafe static STATIC: (); +} |
