From 007032f8504be1274972e4f23afaf0bc431d92d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Dec 2019 19:31:01 +0100 Subject: Refactor --- crates/ra_hir_def/src/nameres/path_resolution.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 378d49455..9b85ae018 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs @@ -181,7 +181,7 @@ impl CrateDefMap { // Since it is a qualified path here, it should not contains legacy macros match self[module.local_id].scope.get(&segment, prefer_module(i)) { - Some(def) => *def, + Some(def) => def, _ => { log::debug!("path segment {:?} not found", segment); return ResolvePathResult::empty(ReachedFixedPoint::No); @@ -243,7 +243,7 @@ impl CrateDefMap { // - std prelude let from_legacy_macro = self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); - let from_scope = self[module].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none); + let from_scope = self[module].scope.get(name, shadow).unwrap_or_else(PerNs::none); let from_extern_prelude = self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); let from_prelude = self.resolve_in_prelude(db, name, shadow); @@ -256,8 +256,7 @@ impl CrateDefMap { name: &Name, shadow: BuiltinShadowMode, ) -> PerNs { - let from_crate_root = - self[self.root].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none); + let from_crate_root = self[self.root].scope.get(name, shadow).unwrap_or_else(PerNs::none); let from_extern_prelude = self.resolve_name_in_extern_prelude(name); from_crate_root.or(from_extern_prelude) @@ -278,7 +277,7 @@ impl CrateDefMap { keep = db.crate_def_map(prelude.krate); &keep }; - def_map[prelude.local_id].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none) + def_map[prelude.local_id].scope.get(name, shadow).unwrap_or_else(PerNs::none) } else { PerNs::none() } -- cgit v1.2.3 From 7c405c01567e814f18ebf8bdc6aa1f8f694919f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Dec 2019 19:32:35 +0100 Subject: Simplify --- crates/ra_hir_def/src/nameres/path_resolution.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 9b85ae018..695014c7b 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs @@ -180,13 +180,7 @@ impl CrateDefMap { } // Since it is a qualified path here, it should not contains legacy macros - match self[module.local_id].scope.get(&segment, prefer_module(i)) { - Some(def) => def, - _ => { - log::debug!("path segment {:?} not found", segment); - return ResolvePathResult::empty(ReachedFixedPoint::No); - } - } + self[module.local_id].scope.get(&segment, prefer_module(i)) } ModuleDefId::AdtId(AdtId::EnumId(e)) => { // enum variant @@ -243,7 +237,7 @@ impl CrateDefMap { // - std prelude let from_legacy_macro = self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); - let from_scope = self[module].scope.get(name, shadow).unwrap_or_else(PerNs::none); + let from_scope = self[module].scope.get(name, shadow); let from_extern_prelude = self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); let from_prelude = self.resolve_in_prelude(db, name, shadow); @@ -256,7 +250,7 @@ impl CrateDefMap { name: &Name, shadow: BuiltinShadowMode, ) -> PerNs { - let from_crate_root = self[self.root].scope.get(name, shadow).unwrap_or_else(PerNs::none); + let from_crate_root = self[self.root].scope.get(name, shadow); let from_extern_prelude = self.resolve_name_in_extern_prelude(name); from_crate_root.or(from_extern_prelude) @@ -277,7 +271,7 @@ impl CrateDefMap { keep = db.crate_def_map(prelude.krate); &keep }; - def_map[prelude.local_id].scope.get(name, shadow).unwrap_or_else(PerNs::none) + def_map[prelude.local_id].scope.get(name, shadow) } else { PerNs::none() } -- cgit v1.2.3 From e424545c0f5cbaf135c52764169ea20df7d07d35 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Dec 2019 20:12:23 +0100 Subject: Rudimentary name resolution for local items --- 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 4f1fd4801..b9f40d3dd 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -446,7 +446,7 @@ where let scope = &mut self.def_map.modules[module_id].scope; let mut changed = false; for (name, res) in resolutions { - changed |= scope.push_res(name.clone(), res); + changed |= scope.push_res(name.clone(), *res); } if !changed { -- cgit v1.2.3