about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-29 05:04:31 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-29 05:20:40 +0000
commit4fe94e0be65865bef1d0283873158baa523afddc (patch)
tree53c10dc8ad7beee5595e0f2d26b5dadc7d0f334f /src
parentc14ff2884dc46a8a0ef7f5916b4730a4e516d9ab (diff)
downloadrust-4fe94e0be65865bef1d0283873158baa523afddc.tar.gz
rust-4fe94e0be65865bef1d0283873158baa523afddc.zip
Future proof the AST for `union`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/lowering.rs1
-rw-r--r--src/librustc/hir/map/def_collector.rs4
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs2
-rw-r--r--src/librustc_resolve/lib.rs1
-rw-r--r--src/libsyntax/ast.rs5
-rw-r--r--src/libsyntax/config.rs3
-rw-r--r--src/libsyntax/fold.rs4
-rw-r--r--src/libsyntax/print/pprust.rs5
-rw-r--r--src/libsyntax/visit.rs3
9 files changed, 24 insertions, 4 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 24792e634a5..6739d3f662a 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -638,6 +638,7 @@ impl<'a> LoweringContext<'a> {
                 let struct_def = self.lower_variant_data(struct_def);
                 hir::ItemStruct(struct_def, self.lower_generics(generics))
             }
+            ItemKind::Union(..) => panic!("`union` is not yet implemented"),
             ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
                 hir::ItemDefaultImpl(self.lower_unsafety(unsafety),
                                      self.lower_trait_ref(trait_ref))
diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs
index 752b0e9a253..77567fc7a46 100644
--- a/src/librustc/hir/map/def_collector.rs
+++ b/src/librustc/hir/map/def_collector.rs
@@ -133,7 +133,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
         let def_data = match i.node {
             ItemKind::DefaultImpl(..) | ItemKind::Impl(..) =>
                 DefPathData::Impl,
-            ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
+            ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
             ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
                 DefPathData::TypeNs(i.ident.name.as_str()),
             ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
@@ -164,7 +164,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
                         });
                     }
                 }
-                ItemKind::Struct(ref struct_def, _) => {
+                ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
                     // If this is a tuple-like struct, register the constructor.
                     if !struct_def.is_struct() {
                         this.create_def(struct_def.id(),
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index 12c55b3ac17..71b00218e7c 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -275,6 +275,8 @@ impl<'b> Resolver<'b> {
                 self.structs.insert(item_def_id, field_names);
             }
 
+            ItemKind::Union(..) => panic!("`union` is not yet implemented"),
+
             ItemKind::DefaultImpl(_, _) | ItemKind::Impl(..) => {}
 
             ItemKind::Trait(_, _, _, ref items) => {
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 5641a50ccac..b5cf680cc12 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -1619,6 +1619,7 @@ impl<'a> Resolver<'a> {
             ItemKind::Enum(_, ref generics) |
             ItemKind::Ty(_, ref generics) |
             ItemKind::Struct(_, ref generics) |
+            ItemKind::Union(_, ref generics) |
             ItemKind::Fn(_, _, _, _, ref generics, _) => {
                 self.with_type_parameter_rib(HasTypeParameters(generics, ItemRibKind),
                                              |this| visit::walk_item(this, item));
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index c0994ccb2ac..fcb99444957 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1883,6 +1883,10 @@ pub enum ItemKind {
     ///
     /// E.g. `struct Foo<A> { x: A }`
     Struct(VariantData, Generics),
+    /// A union definition (`union` or `pub union`).
+    ///
+    /// E.g. `union Foo<A, B> { x: A, y: B }`
+    Union(VariantData, Generics), // FIXME: not yet implemented
     /// A Trait declaration (`trait` or `pub trait`).
     ///
     /// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }`
@@ -1919,6 +1923,7 @@ impl ItemKind {
             ItemKind::Ty(..) => "type alias",
             ItemKind::Enum(..) => "enum",
             ItemKind::Struct(..) => "struct",
+            ItemKind::Union(..) => "union",
             ItemKind::Trait(..) => "trait",
             ItemKind::Mac(..) |
             ItemKind::Impl(..) |
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs
index ff1ecd44371..69a97917652 100644
--- a/src/libsyntax/config.rs
+++ b/src/libsyntax/config.rs
@@ -180,6 +180,9 @@ impl<'a> fold::Folder for StripUnconfigured<'a> {
             ast::ItemKind::Struct(def, generics) => {
                 ast::ItemKind::Struct(fold_struct(self, def), generics)
             }
+            ast::ItemKind::Union(def, generics) => {
+                ast::ItemKind::Union(fold_struct(self, def), generics)
+            }
             ast::ItemKind::Enum(def, generics) => {
                 let variants = def.variants.into_iter().filter_map(|v| {
                     self.configure(v).map(|v| {
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index fad0b6f65a7..7500bfe9caa 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -885,6 +885,10 @@ pub fn noop_fold_item_kind<T: Folder>(i: ItemKind, folder: &mut T) -> ItemKind {
             let struct_def = folder.fold_variant_data(struct_def);
             ItemKind::Struct(struct_def, folder.fold_generics(generics))
         }
+        ItemKind::Union(struct_def, generics) => {
+            let struct_def = folder.fold_variant_data(struct_def);
+            ItemKind::Union(struct_def, folder.fold_generics(generics))
+        }
         ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
             ItemKind::DefaultImpl(unsafety, folder.fold_trait_ref((*trait_ref).clone()))
         }
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 99c00789219..8563d27908d 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1251,7 +1251,10 @@ impl<'a> State<'a> {
                 try!(self.head(&visibility_qualified(&item.vis, "struct")));
                 try!(self.print_struct(&struct_def, generics, item.ident, item.span, true));
             }
-
+            ast::ItemKind::Union(ref struct_def, ref generics) => {
+                try!(self.head(&visibility_qualified(&item.vis, "union")));
+                try!(self.print_struct(&struct_def, generics, item.ident, item.span, true));
+            }
             ast::ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
                 try!(self.head(""));
                 try!(self.print_visibility(&item.vis));
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index b2d47996659..efd9b027504 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -278,7 +278,8 @@ pub fn walk_item<V: Visitor>(visitor: &mut V, item: &Item) {
             visitor.visit_ty(typ);
             walk_list!(visitor, visit_impl_item, impl_items);
         }
-        ItemKind::Struct(ref struct_definition, ref generics) => {
+        ItemKind::Struct(ref struct_definition, ref generics) |
+        ItemKind::Union(ref struct_definition, ref generics) => {
             visitor.visit_generics(generics);
             visitor.visit_variant_data(struct_definition, item.ident,
                                      generics, item.id, item.span);