Skip to content

Commit e71f89d

Browse files
committed
XXX: redoing Struct/Union/TraitAlias
1 parent 19db44f commit e71f89d

File tree

20 files changed

+162
-137
lines changed

20 files changed

+162
-137
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,18 @@ pub struct Enum {
28102810
pub generics: Generics,
28112811
}
28122812

2813+
#[derive(Clone, Encodable, Decodable, Debug)]
2814+
pub struct Struct {
2815+
pub vdata: VariantData,
2816+
pub generics: Generics,
2817+
}
2818+
2819+
#[derive(Clone, Encodable, Decodable, Debug)]
2820+
pub struct TraitAlias {
2821+
pub generics: Generics,
2822+
pub bounds: GenericBounds,
2823+
}
2824+
28132825
#[derive(Clone, Encodable, Decodable, Debug)]
28142826
pub enum ItemKind {
28152827
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
@@ -2855,19 +2867,19 @@ pub enum ItemKind {
28552867
/// A struct definition (`struct`).
28562868
///
28572869
/// E.g., `struct Foo<A> { x: A }`.
2858-
Struct(VariantData, Box<Generics>),
2870+
Struct(Box<Struct>),
28592871
/// A union definition (`union`).
28602872
///
28612873
/// E.g., `union Foo<A, B> { x: A, y: B }`.
2862-
Union(VariantData, Box<Generics>),
2874+
Union(Box<Struct>),
28632875
/// A trait declaration (`trait`).
28642876
///
28652877
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
28662878
Trait(Box<Trait>),
28672879
/// Trait alias
28682880
///
28692881
/// E.g., `trait Foo = Bar + Quux;`.
2870-
TraitAlias(Box<Generics>, GenericBounds),
2882+
TraitAlias(Box<TraitAlias>),
28712883
/// An implementation.
28722884
///
28732885
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
@@ -2918,10 +2930,10 @@ impl ItemKind {
29182930
Self::Fn(box Fn { generics, .. })
29192931
| Self::TyAlias(box TyAlias { generics, .. })
29202932
| Self::Enum(box Enum { generics, .. })
2921-
| Self::Struct(_, box generics)
2922-
| Self::Union(_, box generics)
2933+
| Self::Struct(box Struct { generics, .. })
2934+
| Self::Union(box Struct { generics, .. })
29232935
| Self::Trait(box Trait { generics, .. })
2924-
| Self::TraitAlias(box generics, _)
2936+
| Self::TraitAlias(box TraitAlias { generics, .. })
29252937
| Self::Impl(box Impl { generics, .. }) => Some(generics),
29262938
_ => None,
29272939
}
@@ -3045,8 +3057,8 @@ mod size_asserts {
30453057
static_assert_size!(GenericBound, 88);
30463058
static_assert_size!(Generics, 72);
30473059
static_assert_size!(Impl, 200);
3048-
static_assert_size!(Item, 136);
3049-
static_assert_size!(ItemKind, 48);
3060+
static_assert_size!(Item, 120);
3061+
static_assert_size!(ItemKind, 32);
30503062
static_assert_size!(Lit, 48);
30513063
static_assert_size!(Pat, 120);
30523064
static_assert_size!(Path, 40);

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,9 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10521052
variants.flat_map_in_place(|variant| vis.flat_map_variant(variant));
10531053
vis.visit_generics(generics);
10541054
}
1055-
ItemKind::Struct(variant_data, generics) | ItemKind::Union(variant_data, generics) => {
1056-
vis.visit_variant_data(variant_data);
1055+
ItemKind::Struct(box Struct { vdata, generics })
1056+
| ItemKind::Union(box Struct { vdata, generics }) => {
1057+
vis.visit_variant_data(vdata);
10571058
vis.visit_generics(generics);
10581059
}
10591060
ItemKind::Impl(box Impl {
@@ -1081,7 +1082,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10811082
visit_bounds(bounds, vis);
10821083
items.flat_map_in_place(|item| vis.flat_map_trait_item(item));
10831084
}
1084-
ItemKind::TraitAlias(generics, bounds) => {
1085+
ItemKind::TraitAlias(box TraitAlias { generics, bounds }) => {
10851086
vis.visit_generics(generics);
10861087
visit_bounds(bounds, vis);
10871088
}

compiler/rustc_ast/src/visit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
342342
visitor.visit_ty(self_ty);
343343
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
344344
}
345-
ItemKind::Struct(ref struct_definition, ref generics)
346-
| ItemKind::Union(ref struct_definition, ref generics) => {
345+
ItemKind::Struct(box Struct { ref vdata, ref generics })
346+
| ItemKind::Union(box Struct { ref vdata, ref generics }) => {
347347
visitor.visit_generics(generics);
348-
visitor.visit_variant_data(struct_definition);
348+
visitor.visit_variant_data(vdata);
349349
}
350350
ItemKind::Trait(box Trait {
351351
unsafety: _,
@@ -358,7 +358,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
358358
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
359359
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
360360
}
361-
ItemKind::TraitAlias(ref generics, ref bounds) => {
361+
ItemKind::TraitAlias(box TraitAlias { ref generics, ref bounds }) => {
362362
visitor.visit_generics(generics);
363363
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
364364
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
335335
);
336336
hir::ItemKind::Enum(hir::EnumDef { variants }, generics)
337337
}
338-
ItemKind::Struct(ref struct_def, ref generics) => {
339-
let (generics, struct_def) = self.lower_generics(
338+
ItemKind::Struct(box Struct { ref vdata, ref generics }) => {
339+
let (generics, vdata) = self.lower_generics(
340340
generics,
341341
id,
342342
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
343-
|this| this.lower_variant_data(hir_id, struct_def),
343+
|this| this.lower_variant_data(hir_id, vdata),
344344
);
345-
hir::ItemKind::Struct(struct_def, generics)
345+
hir::ItemKind::Struct(vdata, generics)
346346
}
347-
ItemKind::Union(ref vdata, ref generics) => {
347+
ItemKind::Union(box Struct { ref vdata, ref generics }) => {
348348
let (generics, vdata) = self.lower_generics(
349349
generics,
350350
id,
@@ -441,7 +441,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
441441
);
442442
hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, items)
443443
}
444-
ItemKind::TraitAlias(ref generics, ref bounds) => {
444+
ItemKind::TraitAlias(box TraitAlias { ref generics, ref bounds }) => {
445445
let (generics, bounds) = self.lower_generics(
446446
generics,
447447
id,

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12901290
self.check_mod_file_item_asciionly(item.ident);
12911291
}
12921292
}
1293-
ItemKind::Struct(ref vdata, ref generics) => match vdata {
1293+
ItemKind::Struct(box Struct { ref vdata, ref generics }) => match vdata {
12941294
// Duplicating the `Visitor` logic allows catching all cases
12951295
// of `Anonymous(Struct, Union)` outside of a field struct or union.
12961296
//
@@ -1309,7 +1309,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13091309
}
13101310
_ => {}
13111311
},
1312-
ItemKind::Union(ref vdata, ref generics) => {
1312+
ItemKind::Union(box Struct { ref vdata, ref generics }) => {
13131313
if vdata.fields().is_empty() {
13141314
self.err_handler().span_err(item.span, "unions cannot have zero fields");
13151315
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ impl<'a> State<'a> {
243243
ast::ItemKind::Enum(box ast::Enum { ref variants, ref generics }) => {
244244
self.print_enum(variants, generics, item.ident, item.span, &item.vis);
245245
}
246-
ast::ItemKind::Struct(ref struct_def, ref generics) => {
246+
ast::ItemKind::Struct(box ast::Struct { ref vdata, ref generics }) => {
247247
self.head(visibility_qualified(&item.vis, "struct"));
248-
self.print_struct(struct_def, generics, item.ident, item.span, true);
248+
self.print_struct(vdata, generics, item.ident, item.span, true);
249249
}
250-
ast::ItemKind::Union(ref struct_def, ref generics) => {
250+
ast::ItemKind::Union(box ast::Struct { ref vdata, ref generics }) => {
251251
self.head(visibility_qualified(&item.vis, "union"));
252-
self.print_struct(struct_def, generics, item.ident, item.span, true);
252+
self.print_struct(vdata, generics, item.ident, item.span, true);
253253
}
254254
ast::ItemKind::Impl(box ast::Impl {
255255
unsafety,
@@ -337,7 +337,7 @@ impl<'a> State<'a> {
337337
let empty = item.attrs.is_empty() && items.is_empty();
338338
self.bclose(item.span, empty);
339339
}
340-
ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
340+
ast::ItemKind::TraitAlias(box ast::TraitAlias { ref generics, ref bounds }) => {
341341
self.head(visibility_qualified(&item.vis, "trait"));
342342
self.print_ident(item.ident);
343343
self.print_generic_params(&generics.params);
@@ -455,19 +455,19 @@ impl<'a> State<'a> {
455455

456456
fn print_struct(
457457
&mut self,
458-
struct_def: &ast::VariantData,
458+
variant_data: &ast::VariantData,
459459
generics: &ast::Generics,
460460
ident: Ident,
461461
span: rustc_span::Span,
462462
print_finalizer: bool,
463463
) {
464464
self.print_ident(ident);
465465
self.print_generic_params(&generics.params);
466-
match struct_def {
466+
match variant_data {
467467
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
468-
if let ast::VariantData::Tuple(..) = struct_def {
468+
if let ast::VariantData::Tuple(..) = variant_data {
469469
self.popen();
470-
self.commasep(Inconsistent, struct_def.fields(), |s, field| {
470+
self.commasep(Inconsistent, variant_data.fields(), |s, field| {
471471
s.maybe_print_comment(field.span.lo());
472472
s.print_outer_attributes(&field.attrs);
473473
s.print_visibility(&field.vis);

compiler/rustc_builtin_macros/src/deriving/clone.rs

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

5-
use rustc_ast::{self as ast, Enum, Generics, ItemKind, MetaItem, VariantData};
5+
use rustc_ast::{self as ast, Enum, Generics, ItemKind, MetaItem, Struct, VariantData};
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_expand::base::{Annotatable, ExtCtxt};
88
use rustc_span::symbol::{kw, sym, Ident};
@@ -33,8 +33,8 @@ pub fn expand_deriving_clone(
3333
let is_simple;
3434
match *item {
3535
Annotatable::Item(ref annitem) => match annitem.kind {
36-
ItemKind::Struct(_, box Generics { ref params, .. })
37-
| ItemKind::Enum(box Enum { variants: _, generics: Generics { ref params, .. } }) => {
36+
ItemKind::Struct(box Struct { generics: Generics { ref params, .. }, .. })
37+
| ItemKind::Enum(box Enum { generics: Generics { ref params, .. }, .. }) => {
3838
let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
3939
let has_derive_copy = cx.resolver.has_derive_copy(container_id);
4040
if has_derive_copy

0 commit comments

Comments
 (0)