Skip to content

Commit 4716ce7

Browse files
committed
Box StructUnionKind
1 parent a860b64 commit 4716ce7

File tree

18 files changed

+63
-40
lines changed

18 files changed

+63
-40
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,9 @@ pub struct StaticKind(pub P<Ty>, pub Mutability, pub Option<P<Expr>>);
26912691
#[derive(Clone, Encodable, Decodable, Debug)]
26922692
pub struct ConstKind(pub Defaultness, pub P<Ty>, pub Option<P<Expr>>);
26932693

2694+
#[derive(Clone, Encodable, Decodable, Debug)]
2695+
pub struct StructUnionKind(pub VariantData, pub Generics);
2696+
26942697
#[derive(Clone, Encodable, Decodable, Debug)]
26952698
pub enum ItemKind {
26962699
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
@@ -2734,11 +2737,11 @@ pub enum ItemKind {
27342737
/// A struct definition (`struct`).
27352738
///
27362739
/// E.g., `struct Foo<A> { x: A }`.
2737-
Struct(VariantData, Generics),
2740+
Struct(Box<StructUnionKind>),
27382741
/// A union definition (`union`).
27392742
///
27402743
/// E.g., `union Foo<A, B> { x: A, y: B }`.
2741-
Union(VariantData, Generics),
2744+
Union(Box<StructUnionKind>),
27422745
/// A trait declaration (`trait`).
27432746
///
27442747
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
@@ -2761,7 +2764,7 @@ pub enum ItemKind {
27612764
}
27622765

27632766
#[cfg(target_arch = "x86_64")]
2764-
rustc_data_structures::static_assert_size!(ItemKind, 112);
2767+
rustc_data_structures::static_assert_size!(ItemKind, 104);
27652768

27662769
impl ItemKind {
27672770
pub fn article(&self) -> &str {
@@ -2800,8 +2803,8 @@ impl ItemKind {
28002803
Self::Fn(box FnKind(_, _, generics, _))
28012804
| Self::TyAlias(box TyAliasKind(_, generics, ..))
28022805
| Self::Enum(_, generics)
2803-
| Self::Struct(_, generics)
2804-
| Self::Union(_, generics)
2806+
| Self::Struct(box StructUnionKind(_, generics))
2807+
| Self::Union(box StructUnionKind(_, generics))
28052808
| Self::Trait(box TraitKind(_, _, generics, ..))
28062809
| Self::TraitAlias(generics, _)
28072810
| Self::Impl(box ImplKind { generics, .. }) => Some(generics),

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,8 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
930930
variants.flat_map_in_place(|variant| vis.flat_map_variant(variant));
931931
vis.visit_generics(generics);
932932
}
933-
ItemKind::Struct(variant_data, generics) | ItemKind::Union(variant_data, generics) => {
933+
ItemKind::Struct(box StructUnionKind(variant_data, generics))
934+
| ItemKind::Union(box StructUnionKind(variant_data, generics)) => {
934935
vis.visit_variant_data(variant_data);
935936
vis.visit_generics(generics);
936937
}

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
327327
visitor.visit_ty(self_ty);
328328
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
329329
}
330-
ItemKind::Struct(ref struct_definition, ref generics)
331-
| ItemKind::Union(ref struct_definition, ref generics) => {
330+
ItemKind::Struct(box StructUnionKind(ref struct_definition, ref generics))
331+
| ItemKind::Union(box StructUnionKind(ref struct_definition, ref generics)) => {
332332
visitor.visit_generics(generics);
333333
visitor.visit_variant_data(struct_definition);
334334
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
363363
},
364364
self.lower_generics(generics, ImplTraitContext::disallowed()),
365365
),
366-
ItemKind::Struct(ref struct_def, ref generics) => {
366+
ItemKind::Struct(box StructUnionKind(ref struct_def, ref generics)) => {
367367
let struct_def = self.lower_variant_data(struct_def);
368368
hir::ItemKind::Struct(
369369
struct_def,
370370
self.lower_generics(generics, ImplTraitContext::disallowed()),
371371
)
372372
}
373-
ItemKind::Union(ref vdata, ref generics) => {
373+
ItemKind::Union(box StructUnionKind(ref vdata, ref generics)) => {
374374
let vdata = self.lower_variant_data(vdata);
375375
hir::ItemKind::Union(
376376
vdata,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
498498
let hir_id = self.lctx.allocate_hir_id_counter(item.id);
499499

500500
match item.kind {
501-
ItemKind::Struct(_, ref generics)
502-
| ItemKind::Union(_, ref generics)
501+
ItemKind::Struct(box StructUnionKind(_, ref generics))
502+
| ItemKind::Union(box StructUnionKind(_, ref generics))
503503
| ItemKind::Enum(_, ref generics)
504504
| ItemKind::TyAlias(box TyAliasKind(_, ref generics, ..))
505505
| ItemKind::Trait(box TraitKind(_, _, ref generics, ..)) => {

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10631063
self.check_mod_file_item_asciionly(item.ident);
10641064
}
10651065
}
1066-
ItemKind::Union(ref vdata, _) => {
1066+
ItemKind::Union(box StructUnionKind(ref vdata, _)) => {
10671067
if let VariantData::Tuple(..) | VariantData::Unit(..) = vdata {
10681068
self.err_handler()
10691069
.span_err(item.span, "tuple and unit unions are not permitted");

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,11 +1182,11 @@ impl<'a> State<'a> {
11821182
ast::ItemKind::Enum(ref enum_definition, ref params) => {
11831183
self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis);
11841184
}
1185-
ast::ItemKind::Struct(ref struct_def, ref generics) => {
1185+
ast::ItemKind::Struct(box ast::StructUnionKind(ref struct_def, ref generics)) => {
11861186
self.head(visibility_qualified(&item.vis, "struct"));
11871187
self.print_struct(struct_def, generics, item.ident, item.span, true);
11881188
}
1189-
ast::ItemKind::Union(ref struct_def, ref generics) => {
1189+
ast::ItemKind::Union(box ast::StructUnionKind(ref struct_def, ref generics)) => {
11901190
self.head(visibility_qualified(&item.vis, "union"));
11911191
self.print_struct(struct_def, generics, item.ident, item.span, true);
11921192
}

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use crate::deriving::generic::*;
33
use crate::deriving::path_std;
44

55
use rustc_ast::ptr::P;
6-
use rustc_ast::{self as ast, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData};
6+
use rustc_ast::{
7+
self as ast, Expr, GenericArg, Generics, ItemKind, MetaItem, StructUnionKind, VariantData,
8+
};
79
use rustc_expand::base::{Annotatable, ExtCtxt};
810
use rustc_span::symbol::{kw, sym, Ident, Symbol};
911
use rustc_span::Span;
@@ -34,7 +36,7 @@ pub fn expand_deriving_clone(
3436
let is_shallow;
3537
match *item {
3638
Annotatable::Item(ref annitem) => match annitem.kind {
37-
ItemKind::Struct(_, Generics { ref params, .. })
39+
ItemKind::Struct(box StructUnionKind(_, Generics { ref params, .. }))
3840
| ItemKind::Enum(_, Generics { ref params, .. }) => {
3941
let container_id = cx.current_expansion.id.expn_data().parent;
4042
if cx.resolver.has_derive_copy(container_id)

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ impl<'a> TraitDef<'a> {
402402
false
403403
});
404404
let has_no_type_params = match item.kind {
405-
ast::ItemKind::Struct(_, ref generics)
405+
ast::ItemKind::Struct(box ast::StructUnionKind(_, ref generics))
406406
| ast::ItemKind::Enum(_, ref generics)
407-
| ast::ItemKind::Union(_, ref generics) => !generics
407+
| ast::ItemKind::Union(box ast::StructUnionKind(_, ref generics)) => !generics
408408
.params
409409
.iter()
410410
.any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. })),
@@ -415,7 +415,10 @@ impl<'a> TraitDef<'a> {
415415
let use_temporaries = is_packed && always_copy;
416416

417417
let newitem = match item.kind {
418-
ast::ItemKind::Struct(ref struct_def, ref generics) => self.expand_struct_def(
418+
ast::ItemKind::Struct(box ast::StructUnionKind(
419+
ref struct_def,
420+
ref generics,
421+
)) => self.expand_struct_def(
419422
cx,
420423
&struct_def,
421424
item.ident,
@@ -432,7 +435,10 @@ impl<'a> TraitDef<'a> {
432435
// is fine.
433436
self.expand_enum_def(cx, enum_def, item.ident, generics, from_scratch)
434437
}
435-
ast::ItemKind::Union(ref struct_def, ref generics) => {
438+
ast::ItemKind::Union(box ast::StructUnionKind(
439+
ref struct_def,
440+
ref generics,
441+
)) => {
436442
if self.supports_unions {
437443
self.expand_struct_def(
438444
cx,
@@ -1736,7 +1742,9 @@ pub fn is_type_without_fields(item: &Annotatable) -> bool {
17361742
ast::ItemKind::Enum(ref enum_def, _) => {
17371743
enum_def.variants.iter().all(|v| v.data.fields().is_empty())
17381744
}
1739-
ast::ItemKind::Struct(ref variant_data, _) => variant_data.fields().is_empty(),
1745+
ast::ItemKind::Struct(box ast::StructUnionKind(ref variant_data, _)) => {
1746+
variant_data.fields().is_empty()
1747+
}
17401748
_ => false,
17411749
}
17421750
} else {

compiler/rustc_builtin_macros/src/deriving/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_ast as ast;
44
use rustc_ast::ptr::P;
5-
use rustc_ast::{ImplKind, ItemKind, MetaItem};
5+
use rustc_ast::{ImplKind, ItemKind, MetaItem, StructUnionKind};
66
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
77
use rustc_span::symbol::{sym, Ident, Symbol};
88
use rustc_span::Span;
@@ -121,7 +121,8 @@ fn inject_impl_of_structural_trait(
121121
};
122122

123123
let generics = match item.kind {
124-
ItemKind::Struct(_, ref generics) | ItemKind::Enum(_, ref generics) => generics,
124+
ItemKind::Struct(box StructUnionKind(_, ref generics))
125+
| ItemKind::Enum(_, ref generics) => generics,
125126
// Do not inject `impl Structural for Union`. (`PartialEq` does not
126127
// support unions, so we will see error downstream.)
127128
ItemKind::Union(..) => return,

0 commit comments

Comments
 (0)