]> git.lizzy.rs Git - rust.git/commitdiff
Add unions to AST
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 16 Jul 2016 21:15:15 +0000 (00:15 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 3 Sep 2016 10:37:25 +0000 (13:37 +0300)
src/librustc_passes/ast_validation.rs
src/libsyntax/ast.rs
src/libsyntax/diagnostics/macros.rs

index dde1a4a759563dffd179aa7ede1cfe538cfb911f..b8284f5dcf10d0758aaf53f822acade94d03f5ae 100644 (file)
@@ -196,6 +196,16 @@ fn visit_item(&mut self, item: &Item) {
                 // Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
                 attr::first_attr_value_str_by_name(&item.attrs, "path");
             }
+            ItemKind::Union(ref vdata, _) => {
+                if !vdata.is_struct() {
+                    self.err_handler().span_err(item.span,
+                                                "tuple and unit unions are not permitted");
+                }
+                if vdata.fields().len() == 0 {
+                    self.err_handler().span_err(item.span,
+                                                "unions cannot have zero fields");
+                }
+            }
             _ => {}
         }
 
index fcb99444957c4aaddf75cbd5fb930b1c641e7b97..4394fb0e1431263d64e2e04134fdfaa45263d811 100644 (file)
@@ -1886,7 +1886,7 @@ pub enum ItemKind {
     /// A union definition (`union` or `pub union`).
     ///
     /// E.g. `union Foo<A, B> { x: A, y: B }`
-    Union(VariantData, Generics), // FIXME: not yet implemented
+    Union(VariantData, Generics),
     /// A Trait declaration (`trait` or `pub trait`).
     ///
     /// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }`
index 25e0428248df4f7a9a6d03ad9ff75babb52582f5..e2a7ec0a33de1be6ce5a6f97e04d6b9098e86dab 100644 (file)
@@ -107,6 +107,13 @@ macro_rules! help {
     })
 }
 
+#[macro_export]
+macro_rules! unimplemented_unions {
+    () => ({
+        panic!("unions are not fully implemented");
+    })
+}
+
 #[macro_export]
 macro_rules! register_diagnostics {
     ($($code:tt),*) => (