diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-08-06 21:56:02 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-09-03 13:37:25 +0300 |
| commit | 35d52a003bf0997d31378796bf59cc66c3ae7683 (patch) | |
| tree | 1b9daa6f6f3ad8d4d151f1225a9d8f1a186c3a4e /src/librustc_resolve | |
| parent | 4001c039de931f4e5ad5318b12e333ef30c52d1b (diff) | |
| download | rust-35d52a003bf0997d31378796bf59cc66c3ae7683.tar.gz rust-35d52a003bf0997d31378796bf59cc66c3ae7683.zip | |
Add unions to definition map
Diffstat (limited to 'src/librustc_resolve')
| -rw-r--r-- | src/librustc_resolve/build_reduced_graph.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 3e9b37f0a95..8e97870c21a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -278,7 +278,19 @@ impl<'b> Resolver<'b> { self.structs.insert(item_def_id, field_names); } - ItemKind::Union(..) => panic!("`union` is not yet implemented"), + ItemKind::Union(ref vdata, _) => { + let def = Def::Union(self.definitions.local_def_id(item.id)); + self.define(parent, name, TypeNS, (def, sp, vis)); + + // Record the def ID and fields of this union. + let field_names = vdata.fields().iter().enumerate().map(|(index, field)| { + self.resolve_visibility(&field.vis); + field.ident.map(|ident| ident.name) + .unwrap_or_else(|| token::intern(&index.to_string())) + }).collect(); + let item_def_id = self.definitions.local_def_id(item.id); + self.structs.insert(item_def_id, field_names); + } ItemKind::DefaultImpl(_, _) | ItemKind::Impl(..) => {} @@ -461,6 +473,13 @@ impl<'b> Resolver<'b> { let fields = self.session.cstore.struct_field_names(def_id); self.structs.insert(def_id, fields); } + Def::Union(def_id) => { + let _ = self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis)); + + // Record the def ID and fields of this union. + let fields = self.session.cstore.struct_field_names(def_id); + self.structs.insert(def_id, fields); + } Def::Struct(..) => {} Def::Local(..) | Def::PrimTy(..) | |
