Skip to content

Commit 832109b

Browse files
authored
Rollup merge of rust-lang#126767 - compiler-errors:static-foreign-item, r=spastorino
`StaticForeignItem` and `StaticItem` are the same The struct `StaticItem` and `StaticForeignItem` are the same, so remove `StaticForeignItem`. Having them be separate is unique to `static` items -- unlike `ForeignItemKind::{Fn,TyAlias}`, which use the normal AST item. r? `@spastorino` or `@oli-obk`
2 parents a9859a0 + 3e59f0c commit 832109b

File tree

9 files changed

+10
-67
lines changed

9 files changed

+10
-67
lines changed

compiler/rustc_ast/src/ast.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -3184,38 +3184,6 @@ pub struct StaticItem {
31843184
pub expr: Option<P<Expr>>,
31853185
}
31863186

3187-
/// A static item in `extern` block.
3188-
// This struct is identical to StaticItem for now but it's going to have a safety attribute.
3189-
#[derive(Clone, Encodable, Decodable, Debug)]
3190-
pub struct StaticForeignItem {
3191-
pub ty: P<Ty>,
3192-
pub safety: Safety,
3193-
pub mutability: Mutability,
3194-
pub expr: Option<P<Expr>>,
3195-
}
3196-
3197-
impl From<StaticItem> for StaticForeignItem {
3198-
fn from(static_item: StaticItem) -> StaticForeignItem {
3199-
StaticForeignItem {
3200-
ty: static_item.ty,
3201-
safety: static_item.safety,
3202-
mutability: static_item.mutability,
3203-
expr: static_item.expr,
3204-
}
3205-
}
3206-
}
3207-
3208-
impl From<StaticForeignItem> for StaticItem {
3209-
fn from(static_item: StaticForeignItem) -> StaticItem {
3210-
StaticItem {
3211-
ty: static_item.ty,
3212-
safety: static_item.safety,
3213-
mutability: static_item.mutability,
3214-
expr: static_item.expr,
3215-
}
3216-
}
3217-
}
3218-
32193187
#[derive(Clone, Encodable, Decodable, Debug)]
32203188
pub struct ConstItem {
32213189
pub defaultness: Defaultness,
@@ -3430,7 +3398,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
34303398
#[derive(Clone, Encodable, Decodable, Debug)]
34313399
pub enum ForeignItemKind {
34323400
/// A foreign static item (`static FOO: u8`).
3433-
Static(Box<StaticForeignItem>),
3401+
Static(Box<StaticItem>),
34343402
/// An foreign function.
34353403
Fn(Box<Fn>),
34363404
/// An foreign type.

compiler/rustc_ast/src/mut_visit.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1310,12 +1310,7 @@ pub fn noop_flat_map_item<K: NoopVisitItemKind>(
13101310
impl NoopVisitItemKind for ForeignItemKind {
13111311
fn noop_visit(&mut self, visitor: &mut impl MutVisitor) {
13121312
match self {
1313-
ForeignItemKind::Static(box StaticForeignItem {
1314-
ty,
1315-
mutability: _,
1316-
expr,
1317-
safety: _,
1318-
}) => {
1313+
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
13191314
visitor.visit_ty(ty);
13201315
visit_opt(expr, |expr| visitor.visit_expr(expr));
13211316
}

compiler/rustc_ast/src/visit.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,7 @@ impl WalkItemKind for ForeignItemKind {
672672
) -> V::Result {
673673
let &Item { id, span, ident, ref vis, .. } = item;
674674
match self {
675-
ForeignItemKind::Static(box StaticForeignItem {
676-
ty,
677-
mutability: _,
678-
expr,
679-
safety: _,
680-
}) => {
675+
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
681676
try_visit!(visitor.visit_ty(ty));
682677
visit_opt!(visitor, visit_expr, expr);
683678
}

compiler/rustc_ast_lowering/src/item.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
664664

665665
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics, safety)
666666
}
667-
ForeignItemKind::Static(box StaticForeignItem {
668-
ty,
669-
mutability,
670-
expr: _,
671-
safety,
672-
}) => {
667+
ForeignItemKind::Static(box StaticItem { ty, mutability, expr: _, safety }) => {
673668
let ty = self
674669
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
675670
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12321232
self.check_foreign_ty_genericless(generics, where_clauses);
12331233
self.check_foreign_item_ascii_only(fi.ident);
12341234
}
1235-
ForeignItemKind::Static(box StaticForeignItem { expr, safety, .. }) => {
1235+
ForeignItemKind::Static(box StaticItem { expr, safety, .. }) => {
12361236
self.check_foreign_item_safety(fi.span, *safety);
12371237
self.check_foreign_kind_bodyless(fi.ident, "static", expr.as_ref().map(|b| b.span));
12381238
self.check_foreign_item_ascii_only(fi.ident);

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ impl<'a> State<'a> {
3737
ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
3838
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
3939
}
40-
ast::ForeignItemKind::Static(box ast::StaticForeignItem {
41-
ty,
42-
mutability,
43-
expr,
44-
safety,
45-
}) => {
40+
ast::ForeignItemKind::Static(box ast::StaticItem { ty, mutability, expr, safety }) => {
4641
self.print_safety(*safety);
4742
self.print_item_const(
4843
ident,

compiler/rustc_parse/src/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ impl<'a> Parser<'a> {
12281228
ident_span: ident.span,
12291229
const_span,
12301230
});
1231-
ForeignItemKind::Static(Box::new(StaticForeignItem {
1231+
ForeignItemKind::Static(Box::new(StaticItem {
12321232
ty,
12331233
mutability: Mutability::Not,
12341234
expr,

compiler/rustc_resolve/src/def_collector.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
217217

218218
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
219219
let def_kind = match fi.kind {
220-
ForeignItemKind::Static(box StaticForeignItem {
221-
ty: _,
222-
mutability,
223-
expr: _,
224-
safety,
225-
}) => {
220+
ForeignItemKind::Static(box StaticItem { ty: _, mutability, expr: _, safety }) => {
226221
let safety = match safety {
227222
ast::Safety::Unsafe(_) | ast::Safety::Default => hir::Safety::Unsafe,
228223
ast::Safety::Safe(_) => hir::Safety::Safe,

src/tools/clippy/clippy_utils/src/ast_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
449449
use ForeignItemKind::*;
450450
match (l, r) {
451451
(
452-
Static(box StaticForeignItem {
452+
Static(box StaticItem {
453453
ty: lt,
454454
mutability: lm,
455455
expr: le,
456456
safety: ls,
457457
}),
458-
Static(box StaticForeignItem {
458+
Static(box StaticItem {
459459
ty: rt,
460460
mutability: rm,
461461
expr: re,

0 commit comments

Comments
 (0)