1
Fork 0

Add unions to AST

This commit is contained in:
Vadim Petrochenkov 2016-07-17 00:15:15 +03:00
parent a029ea343f
commit 1db878fd38
3 changed files with 18 additions and 1 deletions

View file

@ -196,6 +196,16 @@ impl<'a> Visitor for AstValidator<'a> {
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584). // Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
attr::first_attr_value_str_by_name(&item.attrs, "path"); 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");
}
}
_ => {} _ => {}
} }

View file

@ -1886,7 +1886,7 @@ pub enum ItemKind {
/// A union definition (`union` or `pub union`). /// A union definition (`union` or `pub union`).
/// ///
/// E.g. `union Foo<A, B> { x: A, y: B }` /// 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`). /// A Trait declaration (`trait` or `pub trait`).
/// ///
/// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }` /// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }`

View file

@ -107,6 +107,13 @@ macro_rules! help {
}) })
} }
#[macro_export]
macro_rules! unimplemented_unions {
() => ({
panic!("unions are not fully implemented");
})
}
#[macro_export] #[macro_export]
macro_rules! register_diagnostics { macro_rules! register_diagnostics {
($($code:tt),*) => ( ($($code:tt),*) => (