Skip to content

Commit 4001c03

Browse files
committed
Add unions to HIR
1 parent 1db878f commit 4001c03

File tree

15 files changed

+37
-14
lines changed

15 files changed

+37
-14
lines changed

src/librustc/hir/fold.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,10 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
761761
let struct_def = folder.fold_variant_data(struct_def);
762762
ItemStruct(struct_def, folder.fold_generics(generics))
763763
}
764+
ItemUnion(struct_def, generics) => {
765+
let struct_def = folder.fold_variant_data(struct_def);
766+
ItemUnion(struct_def, folder.fold_generics(generics))
767+
}
764768
ItemDefaultImpl(unsafety, ref trait_ref) => {
765769
ItemDefaultImpl(unsafety, folder.fold_trait_ref((*trait_ref).clone()))
766770
}

src/librustc/hir/intravisit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
348348
visitor.visit_ty(typ);
349349
walk_list!(visitor, visit_impl_item, impl_items);
350350
}
351-
ItemStruct(ref struct_definition, ref generics) => {
351+
ItemStruct(ref struct_definition, ref generics) |
352+
ItemUnion(ref struct_definition, ref generics) => {
352353
visitor.visit_generics(generics);
353354
visitor.visit_id(item.id);
354355
visitor.visit_variant_data(struct_definition, item.name, generics, item.id, item.span);

src/librustc/hir/map/def_collector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
302302
let def_data = match i.node {
303303
hir::ItemDefaultImpl(..) | hir::ItemImpl(..) =>
304304
DefPathData::Impl,
305-
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemTrait(..) |
306-
hir::ItemExternCrate(..) | hir::ItemMod(..) | hir::ItemForeignMod(..) |
307-
hir::ItemTy(..) =>
305+
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) |
306+
hir::ItemTrait(..) | hir::ItemExternCrate(..) | hir::ItemMod(..) |
307+
hir::ItemForeignMod(..) | hir::ItemTy(..) =>
308308
DefPathData::TypeNs(i.name.as_str()),
309309
hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) =>
310310
DefPathData::ValueNs(i.name.as_str()),

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10301030
ItemTy(..) => "ty",
10311031
ItemEnum(..) => "enum",
10321032
ItemStruct(..) => "struct",
1033+
ItemUnion(..) => "union",
10331034
ItemTrait(..) => "trait",
10341035
ItemImpl(..) => "impl",
10351036
ItemDefaultImpl(..) => "default impl",

src/librustc/hir/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,8 @@ pub enum Item_ {
14831483
ItemEnum(EnumDef, Generics),
14841484
/// A struct definition, e.g. `struct Foo<A> {x: A}`
14851485
ItemStruct(VariantData, Generics),
1486+
/// A union definition, e.g. `union Foo<A, B> {x: A, y: B}`
1487+
ItemUnion(VariantData, Generics),
14861488
/// Represents a Trait Declaration
14871489
ItemTrait(Unsafety, Generics, TyParamBounds, HirVec<TraitItem>),
14881490

@@ -1512,6 +1514,7 @@ impl Item_ {
15121514
ItemTy(..) => "type alias",
15131515
ItemEnum(..) => "enum",
15141516
ItemStruct(..) => "struct",
1517+
ItemUnion(..) => "union",
15151518
ItemTrait(..) => "trait",
15161519
ItemImpl(..) |
15171520
ItemDefaultImpl(..) => "item",

src/librustc/hir/print.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,10 @@ impl<'a> State<'a> {
752752
self.head(&visibility_qualified(&item.vis, "struct"))?;
753753
self.print_struct(struct_def, generics, item.name, item.span, true)?;
754754
}
755-
755+
hir::ItemUnion(ref struct_def, ref generics) => {
756+
self.head(&visibility_qualified(&item.vis, "union"))?;
757+
self.print_struct(struct_def, generics, item.name, item.span, true)?;
758+
}
756759
hir::ItemDefaultImpl(unsafety, ref trait_ref) => {
757760
self.head("")?;
758761
self.print_visibility(&item.vis)?;

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
269269
hir::ItemMod(..) | hir::ItemForeignMod(..) |
270270
hir::ItemImpl(..) | hir::ItemTrait(..) |
271271
hir::ItemStruct(..) | hir::ItemEnum(..) |
272-
hir::ItemDefaultImpl(..) => {}
272+
hir::ItemUnion(..) | hir::ItemDefaultImpl(..) => {}
273273
}
274274
}
275275
ast_map::NodeTraitItem(trait_method) => {

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> {
156156
hir::ItemTy(_, ref generics) |
157157
hir::ItemEnum(_, ref generics) |
158158
hir::ItemStruct(_, ref generics) |
159+
hir::ItemUnion(_, ref generics) |
159160
hir::ItemTrait(_, ref generics, _, _) |
160161
hir::ItemImpl(_, _, ref generics, _, _, _) => {
161162
// These kinds of items have only early bound lifetime parameters.

src/librustc_metadata/encoder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,9 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
11791179
hir::ItemStruct(ref struct_def, _) => {
11801180
self.encode_addl_struct_info(def_id, struct_def.id(), item);
11811181
}
1182+
hir::ItemUnion(..) => {
1183+
unimplemented_unions!();
1184+
}
11821185
hir::ItemImpl(_, _, _, _, _, ref ast_items) => {
11831186
self.encode_addl_impl_info(def_id, item.id, ast_items);
11841187
}

src/librustc_privacy/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
234234
}
235235
}
236236
// Visit everything except for private fields
237-
hir::ItemStruct(ref struct_def, ref generics) => {
237+
hir::ItemStruct(ref struct_def, ref generics) |
238+
hir::ItemUnion(ref struct_def, ref generics) => {
238239
if item_level.is_some() {
239240
self.reach().visit_generics(generics);
240241
for field in struct_def.fields() {
@@ -1067,8 +1068,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivateItemsInPublicInterfacesVisitor<'a, 'tc
10671068
check.visit_foreign_item(foreign_item);
10681069
}
10691070
}
1070-
// Subitems of structs have their own publicity
1071-
hir::ItemStruct(ref struct_def, ref generics) => {
1071+
// Subitems of structs and unions have their own publicity
1072+
hir::ItemStruct(ref struct_def, ref generics) |
1073+
hir::ItemUnion(ref struct_def, ref generics) => {
10721074
check.required_visibility = item_visibility;
10731075
check.visit_generics(generics);
10741076

0 commit comments

Comments
 (0)