Skip to content

Commit 1db878f

Browse files
committed
Add unions to AST
1 parent a029ea3 commit 1db878f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/librustc_passes/ast_validation.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ impl<'a> Visitor for AstValidator<'a> {
196196
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
197197
attr::first_attr_value_str_by_name(&item.attrs, "path");
198198
}
199+
ItemKind::Union(ref vdata, _) => {
200+
if !vdata.is_struct() {
201+
self.err_handler().span_err(item.span,
202+
"tuple and unit unions are not permitted");
203+
}
204+
if vdata.fields().len() == 0 {
205+
self.err_handler().span_err(item.span,
206+
"unions cannot have zero fields");
207+
}
208+
}
199209
_ => {}
200210
}
201211

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ pub enum ItemKind {
18861886
/// A union definition (`union` or `pub union`).
18871887
///
18881888
/// E.g. `union Foo<A, B> { x: A, y: B }`
1889-
Union(VariantData, Generics), // FIXME: not yet implemented
1889+
Union(VariantData, Generics),
18901890
/// A Trait declaration (`trait` or `pub trait`).
18911891
///
18921892
/// E.g. `trait Foo { .. }` or `trait Foo<T> { .. }`

src/libsyntax/diagnostics/macros.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ macro_rules! help {
107107
})
108108
}
109109

110+
#[macro_export]
111+
macro_rules! unimplemented_unions {
112+
() => ({
113+
panic!("unions are not fully implemented");
114+
})
115+
}
116+
110117
#[macro_export]
111118
macro_rules! register_diagnostics {
112119
($($code:tt),*) => (

0 commit comments

Comments
 (0)