diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-25 14:51:17 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-25 14:51:17 +0000 |
commit | ecd1204804a2a3c8b9b98e4b9d18feef06ab51c7 (patch) | |
tree | d051e9bb71631cca33a1b4c23bf3f2576d1c0f56 /crates/ra_hir_def/src/nameres | |
parent | be00d74c7b61fb82bdade482e95035a21f9dd736 (diff) | |
parent | 1455663ea15ecbfbe87b4b5be6919aa35dd0b260 (diff) |
Merge #2403
2403: Fixme for union fields r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests.rs | 7 |
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 | ||
31 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 31 | pub(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 { | |||
176 | pub(super) enum DefKind { | 176 | pub(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 | ||