Skip to content

Commit 4e1b3ab

Browse files
Print safety correctly in extern static items
1 parent 4f2f477 commit 4e1b3ab

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state/item.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ impl<'a> State<'a> {
3838
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
3939
}
4040
ast::ForeignItemKind::Static(box ast::StaticItem { ty, mutability, expr, safety }) => {
41-
self.print_safety(*safety);
4241
self.print_item_const(
4342
ident,
4443
Some(*mutability),
4544
&ast::Generics::default(),
4645
ty,
4746
expr.as_deref(),
4847
vis,
48+
*safety,
4949
ast::Defaultness::Final,
5050
)
5151
}
@@ -84,10 +84,12 @@ impl<'a> State<'a> {
8484
ty: &ast::Ty,
8585
body: Option<&ast::Expr>,
8686
vis: &ast::Visibility,
87+
safety: ast::Safety,
8788
defaultness: ast::Defaultness,
8889
) {
8990
self.head("");
9091
self.print_visibility(vis);
92+
self.print_safety(safety);
9193
self.print_defaultness(defaultness);
9294
let leading = match mutbl {
9395
None => "const",
@@ -181,6 +183,7 @@ impl<'a> State<'a> {
181183
ty,
182184
body.as_deref(),
183185
&item.vis,
186+
ast::Safety::Default,
184187
ast::Defaultness::Final,
185188
);
186189
}
@@ -192,6 +195,7 @@ impl<'a> State<'a> {
192195
ty,
193196
expr.as_deref(),
194197
&item.vis,
198+
ast::Safety::Default,
195199
*defaultness,
196200
);
197201
}
@@ -549,6 +553,7 @@ impl<'a> State<'a> {
549553
ty,
550554
expr.as_deref(),
551555
vis,
556+
ast::Safety::Default,
552557
*defaultness,
553558
);
554559
}

Diff for: tests/ui/unpretty/extern-static.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ compile-flags: -Zunpretty=normal
2+
//@ check-pass
3+
4+
unsafe extern "C" {
5+
pub unsafe static STATIC: ();
6+
}

Diff for: tests/ui/unpretty/extern-static.stdout

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ compile-flags: -Zunpretty=normal
2+
//@ check-pass
3+
4+
unsafe extern "C" {
5+
pub unsafe static STATIC: ();
6+
}

0 commit comments

Comments
 (0)