diff options
author | Aleksey Kladov <[email protected]> | 2019-12-22 18:31:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-22 18:31:01 +0000 |
commit | 007032f8504be1274972e4f23afaf0bc431d92d5 (patch) | |
tree | e6e6a7ca188f53a7fb9ff41dcd8ca931ceaffc66 /crates | |
parent | 78f7683b9a1c6192b4828ceedb14ed498b241263 (diff) |
Refactor
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/path_resolution.rs | 9 |
2 files changed, 11 insertions, 10 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index f1adc3b58..08d788cc9 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -70,18 +70,20 @@ impl ItemScope { | |||
70 | } | 70 | } |
71 | 71 | ||
72 | /// Get a name from current module scope, legacy macros are not included | 72 | /// Get a name from current module scope, legacy macros are not included |
73 | pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&PerNs> { | 73 | pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<PerNs> { |
74 | match shadow { | 74 | match shadow { |
75 | BuiltinShadowMode::Module => self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)), | 75 | BuiltinShadowMode::Module => { |
76 | self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)).copied() | ||
77 | } | ||
76 | BuiltinShadowMode::Other => { | 78 | BuiltinShadowMode::Other => { |
77 | let item = self.visible.get(name); | 79 | let item = self.visible.get(name).copied(); |
78 | if let Some(def) = item { | 80 | if let Some(def) = item { |
79 | if let Some(ModuleDefId::ModuleId(_)) = def.take_types() { | 81 | if let Some(ModuleDefId::ModuleId(_)) = def.take_types() { |
80 | return BUILTIN_SCOPE.get(name).or(item); | 82 | return BUILTIN_SCOPE.get(name).copied().or(item); |
81 | } | 83 | } |
82 | } | 84 | } |
83 | 85 | ||
84 | item.or_else(|| BUILTIN_SCOPE.get(name)) | 86 | item.or_else(|| BUILTIN_SCOPE.get(name).copied()) |
85 | } | 87 | } |
86 | } | 88 | } |
87 | } | 89 | } |
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 { | |||
181 | 181 | ||
182 | // Since it is a qualified path here, it should not contains legacy macros | 182 | // Since it is a qualified path here, it should not contains legacy macros |
183 | match self[module.local_id].scope.get(&segment, prefer_module(i)) { | 183 | match self[module.local_id].scope.get(&segment, prefer_module(i)) { |
184 | Some(def) => *def, | 184 | Some(def) => def, |
185 | _ => { | 185 | _ => { |
186 | log::debug!("path segment {:?} not found", segment); | 186 | log::debug!("path segment {:?} not found", segment); |
187 | return ResolvePathResult::empty(ReachedFixedPoint::No); | 187 | return ResolvePathResult::empty(ReachedFixedPoint::No); |
@@ -243,7 +243,7 @@ impl CrateDefMap { | |||
243 | // - std prelude | 243 | // - std prelude |
244 | let from_legacy_macro = | 244 | let from_legacy_macro = |
245 | self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); | 245 | self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); |
246 | let from_scope = self[module].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none); | 246 | let from_scope = self[module].scope.get(name, shadow).unwrap_or_else(PerNs::none); |
247 | let from_extern_prelude = | 247 | let from_extern_prelude = |
248 | self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); | 248 | self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); |
249 | let from_prelude = self.resolve_in_prelude(db, name, shadow); | 249 | let from_prelude = self.resolve_in_prelude(db, name, shadow); |
@@ -256,8 +256,7 @@ impl CrateDefMap { | |||
256 | name: &Name, | 256 | name: &Name, |
257 | shadow: BuiltinShadowMode, | 257 | shadow: BuiltinShadowMode, |
258 | ) -> PerNs { | 258 | ) -> PerNs { |
259 | let from_crate_root = | 259 | let from_crate_root = self[self.root].scope.get(name, shadow).unwrap_or_else(PerNs::none); |
260 | self[self.root].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none); | ||
261 | let from_extern_prelude = self.resolve_name_in_extern_prelude(name); | 260 | let from_extern_prelude = self.resolve_name_in_extern_prelude(name); |
262 | 261 | ||
263 | from_crate_root.or(from_extern_prelude) | 262 | from_crate_root.or(from_extern_prelude) |
@@ -278,7 +277,7 @@ impl CrateDefMap { | |||
278 | keep = db.crate_def_map(prelude.krate); | 277 | keep = db.crate_def_map(prelude.krate); |
279 | &keep | 278 | &keep |
280 | }; | 279 | }; |
281 | def_map[prelude.local_id].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none) | 280 | def_map[prelude.local_id].scope.get(name, shadow).unwrap_or_else(PerNs::none) |
282 | } else { | 281 | } else { |
283 | PerNs::none() | 282 | PerNs::none() |
284 | } | 283 | } |