aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-25 14:30:50 +0000
committerAleksey Kladov <[email protected]>2019-11-25 14:50:49 +0000
commit5fd68b592938b6a4c074146c1b22ea0f6908fe26 (patch)
tree3403f802366b9ddf9c9e1c1ff59af3d81e476ad1 /crates/ra_hir_def/src/nameres
parente1c0bdaf75f8d88a5c28b3e44def17d91d4f46b3 (diff)
Fix hir for ast::UnionDef
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs12
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs13
-rw-r--r--crates/ra_hir_def/src/nameres/tests.rs7
3 files changed, 19 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 41becf8df..4ff6f72cf 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -25,7 +25,7 @@ use crate::{
25 per_ns::PerNs, 25 per_ns::PerNs,
26 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, 26 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId,
27 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, 27 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId,
28 StructOrUnionId, TraitId, TypeAliasLoc, UnionId, 28 TraitId, TypeAliasLoc, UnionId,
29}; 29};
30 30
31pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 31pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@@ -698,14 +698,12 @@ where
698 PerNs::values(def.into()) 698 PerNs::values(def.into())
699 } 699 }
700 raw::DefKind::Struct(ast_id) => { 700 raw::DefKind::Struct(ast_id) => {
701 let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); 701 let id = StructId::from_ast_id(ctx, ast_id).into();
702 let s = StructId(id).into(); 702 PerNs::both(id, id)
703 PerNs::both(s, s)
704 } 703 }
705 raw::DefKind::Union(ast_id) => { 704 raw::DefKind::Union(ast_id) => {
706 let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); 705 let id = UnionId::from_ast_id(ctx, ast_id).into();
707 let u = UnionId(id).into(); 706 PerNs::both(id, id)
708 PerNs::both(u, u)
709 } 707 }
710 raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), 708 raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()),
711 raw::DefKind::Const(ast_id) => { 709 raw::DefKind::Const(ast_id) => {
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 401af031c..6eb106094 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -176,7 +176,7 @@ pub(super) struct DefData {
176pub(super) enum DefKind { 176pub(super) enum DefKind {
177 Function(FileAstId<ast::FnDef>), 177 Function(FileAstId<ast::FnDef>),
178 Struct(FileAstId<ast::StructDef>), 178 Struct(FileAstId<ast::StructDef>),
179 Union(FileAstId<ast::StructDef>), 179 Union(FileAstId<ast::UnionDef>),
180 Enum(FileAstId<ast::EnumDef>), 180 Enum(FileAstId<ast::EnumDef>),
181 Const(FileAstId<ast::ConstDef>), 181 Const(FileAstId<ast::ConstDef>),
182 Static(FileAstId<ast::StaticDef>), 182 Static(FileAstId<ast::StaticDef>),
@@ -246,11 +246,12 @@ impl RawItemsCollector {
246 ast::ModuleItem::StructDef(it) => { 246 ast::ModuleItem::StructDef(it) => {
247 let id = self.source_ast_id_map.ast_id(&it); 247 let id = self.source_ast_id_map.ast_id(&it);
248 let name = it.name(); 248 let name = it.name();
249 if it.is_union() { 249 (DefKind::Struct(id), name)
250 (DefKind::Union(id), name) 250 }
251 } else { 251 ast::ModuleItem::UnionDef(it) => {
252 (DefKind::Struct(id), name) 252 let id = self.source_ast_id_map.ast_id(&it);
253 } 253 let name = it.name();
254 (DefKind::Union(id), name)
254 } 255 }
255 ast::ModuleItem::EnumDef(it) => { 256 ast::ModuleItem::EnumDef(it) => {
256 (DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name()) 257 (DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name())
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs
index f502f1cb3..87fcd617c 100644
--- a/crates/ra_hir_def/src/nameres/tests.rs
+++ b/crates/ra_hir_def/src/nameres/tests.rs
@@ -82,6 +82,12 @@ fn crate_def_map_smoke_test() {
82 82
83 //- /foo/bar.rs 83 //- /foo/bar.rs
84 pub struct Baz; 84 pub struct Baz;
85
86 union U {
87 to_be: bool,
88 not_to_be: u8,
89 }
90
85 enum E { V } 91 enum E { V }
86 ", 92 ",
87 ); 93 );
@@ -99,6 +105,7 @@ fn crate_def_map_smoke_test() {
99 ⋮crate::foo::bar 105 ⋮crate::foo::bar
100 ⋮Baz: t v 106 ⋮Baz: t v
101 ⋮E: t 107 ⋮E: t
108 ⋮U: t v
102 "###) 109 "###)
103} 110}
104 111