Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7b82197

Browse files
committedApr 30, 2024··
Handle safe safety keyword for extern block inner items
1 parent 49204d7 commit 7b82197

File tree

58 files changed

+177
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+177
-82
lines changed
 

‎compiler/rustc_ast/src/ast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,8 @@ pub enum Unsafe {
24912491
pub enum Safety {
24922492
/// `unsafe` an item is explicitly marked as `unsafe`.
24932493
Unsafe(Span),
2494+
/// `safe` an item is explicitly marked as `safe`.
2495+
Safe(Span),
24942496
/// Default means no value was provided, it will take a default value given the context in
24952497
/// which is used.
24962498
Default,
@@ -3142,6 +3144,7 @@ pub struct StaticItem {
31423144
#[derive(Clone, Encodable, Decodable, Debug)]
31433145
pub struct StaticForeignItem {
31443146
pub ty: P<Ty>,
3147+
pub safety: Safety,
31453148
pub mutability: Mutability,
31463149
pub expr: Option<P<Expr>>,
31473150
}
@@ -3150,6 +3153,7 @@ impl From<StaticItem> for StaticForeignItem {
31503153
fn from(static_item: StaticItem) -> StaticForeignItem {
31513154
StaticForeignItem {
31523155
ty: static_item.ty,
3156+
safety: Safety::Default,
31533157
mutability: static_item.mutability,
31543158
expr: static_item.expr,
31553159
}

‎compiler/rustc_ast/src/mut_visit.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ fn visit_unsafety<T: MutVisitor>(unsafety: &mut Unsafe, vis: &mut T) {
867867
fn visit_fn_safety<T: MutVisitor>(safety: &mut Safety, vis: &mut T) {
868868
match safety {
869869
Safety::Unsafe(span) => vis.visit_span(span),
870+
Safety::Safe(span) => vis.visit_span(span),
870871
Safety::Default => {}
871872
}
872873
}
@@ -1268,7 +1269,12 @@ pub fn noop_flat_map_item<K: NoopVisitItemKind>(
12681269
impl NoopVisitItemKind for ForeignItemKind {
12691270
fn noop_visit(&mut self, visitor: &mut impl MutVisitor) {
12701271
match self {
1271-
ForeignItemKind::Static(box StaticForeignItem { ty, mutability: _, expr }) => {
1272+
ForeignItemKind::Static(box StaticForeignItem {
1273+
ty,
1274+
mutability: _,
1275+
expr,
1276+
safety: _,
1277+
}) => {
12721278
visitor.visit_ty(ty);
12731279
visit_opt(expr, |expr| visitor.visit_expr(expr));
12741280
}

0 commit comments

Comments
 (0)
Please sign in to comment.