From 5fd68b592938b6a4c074146c1b22ea0f6908fe26 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 Nov 2019 17:30:50 +0300 Subject: Fix hir for ast::UnionDef --- crates/ra_hir_def/src/nameres/collector.rs | 12 +++++------- crates/ra_hir_def/src/nameres/raw.rs | 13 +++++++------ crates/ra_hir_def/src/nameres/tests.rs | 7 +++++++ 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') 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::{ per_ns::PerNs, AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, - StructOrUnionId, TraitId, TypeAliasLoc, UnionId, + TraitId, TypeAliasLoc, UnionId, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { @@ -698,14 +698,12 @@ where PerNs::values(def.into()) } raw::DefKind::Struct(ast_id) => { - let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); - let s = StructId(id).into(); - PerNs::both(s, s) + let id = StructId::from_ast_id(ctx, ast_id).into(); + PerNs::both(id, id) } raw::DefKind::Union(ast_id) => { - let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); - let u = UnionId(id).into(); - PerNs::both(u, u) + let id = UnionId::from_ast_id(ctx, ast_id).into(); + PerNs::both(id, id) } raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()), 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 { pub(super) enum DefKind { Function(FileAstId), Struct(FileAstId), - Union(FileAstId), + Union(FileAstId), Enum(FileAstId), Const(FileAstId), Static(FileAstId), @@ -246,11 +246,12 @@ impl RawItemsCollector { ast::ModuleItem::StructDef(it) => { let id = self.source_ast_id_map.ast_id(&it); let name = it.name(); - if it.is_union() { - (DefKind::Union(id), name) - } else { - (DefKind::Struct(id), name) - } + (DefKind::Struct(id), name) + } + ast::ModuleItem::UnionDef(it) => { + let id = self.source_ast_id_map.ast_id(&it); + let name = it.name(); + (DefKind::Union(id), name) } ast::ModuleItem::EnumDef(it) => { (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() { //- /foo/bar.rs pub struct Baz; + + union U { + to_be: bool, + not_to_be: u8, + } + enum E { V } ", ); @@ -99,6 +105,7 @@ fn crate_def_map_smoke_test() { ⋮crate::foo::bar ⋮Baz: t v ⋮E: t + ⋮U: t v "###) } -- cgit v1.2.3 From 447268ceac497432822e8cf28525a6784f392020 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 27 Nov 2019 01:33:08 +0800 Subject: Hide MacroCallLoc --- crates/ra_hir_def/src/nameres/collector.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 4ff6f72cf..ea3abfdae 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -6,7 +6,7 @@ use hir_expand::{ builtin_macro::find_builtin_macro, name::{self, AsName, Name}, - HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFileKind, + HirFileId, MacroCallId, MacroDefId, MacroDefKind, MacroFileKind, }; use ra_cfg::CfgOptions; use ra_db::{CrateId, FileId}; @@ -480,7 +480,7 @@ where ); if let Some(def) = resolved_res.resolved_def.take_macros() { - let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id }); + let call_id = def.as_call_id(self.db, *ast_id); resolved.push((*module_id, call_id, def)); res = ReachedFixedPoint::No; return false; @@ -773,8 +773,7 @@ where if let Some(macro_def) = mac.path.as_ident().and_then(|name| { self.def_collector.def_map[self.module_id].scope.get_legacy_macro(&name) }) { - let macro_call_id = - self.def_collector.db.intern_macro(MacroCallLoc { def: macro_def, ast_id }); + let macro_call_id = macro_def.as_call_id(self.def_collector.db, ast_id); self.def_collector.collect_macro_expansion(self.module_id, macro_call_id, macro_def); return; -- cgit v1.2.3 From d9a36a736bfb91578a36505e7237212959bb55fe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 21:31:51 +0300 Subject: Rename module_id -> local_id --- crates/ra_hir_def/src/nameres/collector.rs | 14 +++++++------- crates/ra_hir_def/src/nameres/path_resolution.rs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index ea3abfdae..6cd14026b 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -37,7 +37,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); def_map.extern_prelude.insert( dep.as_name(), - ModuleId { krate: dep.crate_id, module_id: dep_def_map.root }.into(), + ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(), ); // look for the prelude @@ -323,7 +323,7 @@ where tested_by!(glob_across_crates); // glob import from other crate => we can just import everything once let item_map = self.db.crate_def_map(m.krate); - let scope = &item_map[m.module_id].scope; + let scope = &item_map[m.local_id].scope; // Module scoped macros is included let items = scope @@ -337,7 +337,7 @@ where // glob import from same crate => we do an initial // import, and then need to propagate any further // additions - let scope = &self.def_map[m.module_id].scope; + let scope = &self.def_map[m.local_id].scope; // Module scoped macros is included let items = scope @@ -349,7 +349,7 @@ where self.update(module_id, Some(import_id), &items); // record the glob import in case we add further items self.glob_imports - .entry(m.module_id) + .entry(m.local_id) .or_default() .push((module_id, import_id)); } @@ -590,7 +590,7 @@ where raw::RawItemKind::Impl(imp) => { let module = ModuleId { krate: self.def_collector.def_map.krate, - module_id: self.module_id, + local_id: self.module_id, }; let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id); @@ -673,7 +673,7 @@ where modules[self.module_id].children.insert(name.clone(), res); let resolution = Resolution { def: PerNs::types( - ModuleId { krate: self.def_collector.def_map.krate, module_id: res }.into(), + ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), ), import: None, }; @@ -683,7 +683,7 @@ where fn define_def(&mut self, def: &raw::DefData) { let module = - ModuleId { krate: self.def_collector.def_map.krate, module_id: self.module_id }; + ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); let name = def.name.clone(); diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 9455f22bb..b72c55bd1 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs @@ -74,19 +74,19 @@ impl CrateDefMap { PathKind::DollarCrate(krate) => { if krate == self.krate { tested_by!(macro_dollar_crate_self); - PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into()) + PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) } else { let def_map = db.crate_def_map(krate); - let module = ModuleId { krate, module_id: def_map.root }; + let module = ModuleId { krate, local_id: def_map.root }; tested_by!(macro_dollar_crate_other); PerNs::types(module.into()) } } PathKind::Crate => { - PerNs::types(ModuleId { krate: self.krate, module_id: self.root }.into()) + PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) } PathKind::Self_ => { - PerNs::types(ModuleId { krate: self.krate, module_id: original_module }.into()) + PerNs::types(ModuleId { krate: self.krate, local_id: original_module }.into()) } // plain import or absolute path in 2015: crate-relative with // fallback to extern prelude (with the simplification in @@ -113,7 +113,7 @@ impl CrateDefMap { } PathKind::Super => { if let Some(p) = self.modules[original_module].parent { - PerNs::types(ModuleId { krate: self.krate, module_id: p }.into()) + PerNs::types(ModuleId { krate: self.krate, local_id: p }.into()) } else { log::debug!("super path in root module"); return ResolvePathResult::empty(ReachedFixedPoint::Yes); @@ -160,7 +160,7 @@ impl CrateDefMap { Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ }; log::debug!("resolving {:?} in other crate", path); let defp_map = db.crate_def_map(module.krate); - let (def, s) = defp_map.resolve_path(db, module.module_id, &path); + let (def, s) = defp_map.resolve_path(db, module.local_id, &path); return ResolvePathResult::with( def, ReachedFixedPoint::Yes, @@ -169,7 +169,7 @@ impl CrateDefMap { } // Since it is a qualified path here, it should not contains legacy macros - match self[module.module_id].scope.get(&segment.name) { + match self[module.local_id].scope.get(&segment.name) { Some(res) => res.def, _ => { log::debug!("path segment {:?} not found", segment.name); @@ -254,7 +254,7 @@ impl CrateDefMap { keep = db.crate_def_map(prelude.krate); &keep }; - def_map[prelude.module_id].scope.get(name).map_or_else(PerNs::none, |res| res.def) + def_map[prelude.local_id].scope.get(name).map_or_else(PerNs::none, |res| res.def) } else { PerNs::none() } -- cgit v1.2.3 From 27b362b05910c81fd5b28f6cd5d2c075311032f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 21:44:38 +0300 Subject: Reformat --- crates/ra_hir_def/src/nameres/collector.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 6cd14026b..603b49738 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -682,8 +682,7 @@ where } fn define_def(&mut self, def: &raw::DefData) { - let module = - ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; + let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); let name = def.name.clone(); -- cgit v1.2.3 From 1d14fd17372b42c3343daf6adc9a520fdf5e9810 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 23:22:20 +0300 Subject: Use Name::missing consistently --- crates/ra_hir_def/src/nameres/collector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 603b49738..fd8245113 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -362,7 +362,7 @@ where .variants .iter() .filter_map(|(local_id, variant_data)| { - let name = variant_data.name.clone()?; + let name = variant_data.name.clone(); let variant = EnumVariantId { parent: e, local_id }; let res = Resolution { def: PerNs::both(variant.into(), variant.into()), -- cgit v1.2.3