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,

compiler/rustc_expand/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ impl<'a> StripUnconfigured<'a> {
455455

456456
pub fn configure_item_kind(&mut self, item: &mut ast::ItemKind) {
457457
match item {
458-
ast::ItemKind::Struct(def, _generics) | ast::ItemKind::Union(def, _generics) => {
458+
ast::ItemKind::Struct(box ast::StructUnionKind(def, _generics))
459+
| ast::ItemKind::Union(box ast::StructUnionKind(def, _generics)) => {
459460
self.configure_variant_data(def)
460461
}
461462
ast::ItemKind::Enum(ast::EnumDef { variants }, _generics) => {

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ impl<'a> Parser<'a> {
11881188
return Err(err);
11891189
};
11901190

1191-
Ok((class_name, ItemKind::Struct(vdata, generics)))
1191+
Ok((class_name, ItemKind::Struct(box StructUnionKind(vdata, generics))))
11921192
}
11931193

11941194
/// Parses `union Foo { ... }`.
@@ -1212,7 +1212,7 @@ impl<'a> Parser<'a> {
12121212
return Err(err);
12131213
};
12141214

1215-
Ok((class_name, ItemKind::Union(vdata, generics)))
1215+
Ok((class_name, ItemKind::Union(box StructUnionKind(vdata, generics))))
12161216
}
12171217

12181218
fn parse_record_struct_body(

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::{Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segmen
1717

1818
use rustc_ast::visit::{self, AssocCtxt, Visitor};
1919
use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
20-
use rustc_ast::{Block, FnKind, ForeignItem, ForeignItemKind, ImplKind, Item, ItemKind, NodeId};
20+
use rustc_ast::{
21+
Block, FnKind, ForeignItem, ForeignItemKind, ImplKind, Item, ItemKind, NodeId, StructUnionKind,
22+
};
2123
use rustc_ast_lowering::ResolverAstLowering;
2224
use rustc_attr as attr;
2325
use rustc_data_structures::sync::Lrc;
@@ -817,7 +819,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
817819
}
818820

819821
// These items live in both the type and value namespaces.
820-
ItemKind::Struct(ref vdata, _) => {
822+
ItemKind::Struct(box StructUnionKind(ref vdata, _)) => {
821823
// Define a name in the type namespace.
822824
let res = Res::Def(DefKind::Struct, def_id);
823825
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
@@ -864,7 +866,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
864866
}
865867
}
866868

867-
ItemKind::Union(ref vdata, _) => {
869+
ItemKind::Union(box StructUnionKind(ref vdata, _)) => {
868870
let res = Res::Def(DefKind::Union, def_id);
869871
self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion));
870872

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
104104

105105
self.with_parent(def, |this| {
106106
match i.kind {
107-
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
107+
ItemKind::Struct(box StructUnionKind(ref struct_def, _))
108+
| ItemKind::Union(box StructUnionKind(ref struct_def, _)) => {
108109
// If this is a unit or tuple-like struct, register the constructor.
109110
if let Some(ctor_hir_id) = struct_def.ctor_id() {
110111
this.create_def(ctor_hir_id, DefPathData::Ctor, i.span);

compiler/rustc_resolve/src/late.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
946946
}
947947

948948
ItemKind::Enum(_, ref generics)
949-
| ItemKind::Struct(_, ref generics)
950-
| ItemKind::Union(_, ref generics) => {
949+
| ItemKind::Struct(box StructUnionKind(_, ref generics))
950+
| ItemKind::Union(box StructUnionKind(_, ref generics)) => {
951951
self.resolve_adt(item, generics);
952952
}
953953

src/tools/clippy/clippy_lints/src/excessive_bools.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::{attr_by_name, in_macro, match_path_ast, span_lint_and_help};
22
use rustc_ast::ast::{
3-
AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, TraitKind, Ty, TyKind,
3+
AssocItemKind, Extern, FnKind, FnSig, ImplKind, Item, ItemKind, StructUnionKind, TraitKind, Ty,
4+
TyKind,
45
};
56
use rustc_lint::{EarlyContext, EarlyLintPass};
67
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -138,7 +139,7 @@ impl EarlyLintPass for ExcessiveBools {
138139
return;
139140
}
140141
match &item.kind {
141-
ItemKind::Struct(variant_data, _) => {
142+
ItemKind::Struct(box StructUnionKind(variant_data, _)) => {
142143
if attr_by_name(&item.attrs, "repr").is_some() {
143144
return;
144145
}

src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::utils::{meets_msrv, snippet_opt, span_lint_and_then};
22
use if_chain::if_chain;
3-
use rustc_ast::ast::{Attribute, Item, ItemKind, StructField, Variant, VariantData, VisibilityKind};
3+
use rustc_ast::ast::{
4+
Attribute, Item, ItemKind, StructField, StructUnionKind, Variant, VariantData, VisibilityKind,
5+
};
46
use rustc_attr as attr;
57
use rustc_errors::Applicability;
68
use rustc_lint::{EarlyContext, EarlyLintPass};
@@ -81,8 +83,8 @@ impl EarlyLintPass for ManualNonExhaustive {
8183
match &item.kind {
8284
ItemKind::Enum(def, _) => {
8385
check_manual_non_exhaustive_enum(cx, item, &def.variants);
84-
},
85-
ItemKind::Struct(variant_data, _) => {
86+
}
87+
ItemKind::Struct(box StructUnionKind(variant_data, _)) => {
8688
if let VariantData::Unit(..) = variant_data {
8789
return;
8890
}

src/tools/clippy/clippy_lints/src/utils/ast_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
256256
},
257257
(Enum(le, lg), Enum(re, rg)) => {
258258
over(&le.variants, &re.variants, |l, r| eq_variant(l, r)) && eq_generics(lg, rg)
259-
},
260-
(Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => {
259+
}
260+
(Struct(box StructUnionKind(lv, lg)), Struct(box StructUnionKind(rv, rg)))
261+
| (Union(box StructUnionKind(lv, lg)), Union(box StructUnionKind(rv, rg))) => {
261262
eq_variant_data(lv, rv) && eq_generics(lg, rg)
262263
}
263264
(Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => {

0 commit comments

Comments
 (0)