Future proof the AST for union
.
This commit is contained in:
parent
c14ff2884d
commit
4fe94e0be6
@ -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))
|
||||
|
@ -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(),
|
||||
|
@ -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) => {
|
||||
|
@ -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));
|
||||
|
@ -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(..) |
|
||||
|
@ -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| {
|
||||
|
@ -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()))
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user