aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/path_resolution.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-14 18:16:48 +0000
committerGitHub <[email protected]>2019-12-14 18:16:48 +0000
commitd6223253b628b279f9ddae8f83f7173d01f6b32c (patch)
tree12f2ccc5c52c1c0b67932d3a35fe18668b8e5d62 /crates/ra_hir_def/src/nameres/path_resolution.rs
parent202ad1e2d9376565cb273cf085be600ed10e5a93 (diff)
parent2619950b3b405324ab1c1745876165c834b3b4b9 (diff)
Merge #2561
2561: Split generic and non-generic paths r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres/path_resolution.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index aab4b1dd9..4a249e7e7 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -17,7 +17,7 @@ use test_utils::tested_by;
17use crate::{ 17use crate::{
18 db::DefDatabase, 18 db::DefDatabase,
19 nameres::{BuiltinShadowMode, CrateDefMap}, 19 nameres::{BuiltinShadowMode, CrateDefMap},
20 path::{Path, PathKind}, 20 path::{ModPath, PathKind},
21 per_ns::PerNs, 21 per_ns::PerNs,
22 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, 22 AdtId, CrateId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
23}; 23};
@@ -69,7 +69,7 @@ impl CrateDefMap {
69 db: &impl DefDatabase, 69 db: &impl DefDatabase,
70 mode: ResolveMode, 70 mode: ResolveMode,
71 original_module: LocalModuleId, 71 original_module: LocalModuleId,
72 path: &Path, 72 path: &ModPath,
73 shadow: BuiltinShadowMode, 73 shadow: BuiltinShadowMode,
74 ) -> ResolvePathResult { 74 ) -> ResolvePathResult {
75 // if it is not the last segment, we prefer the module to the builtin 75 // if it is not the last segment, we prefer the module to the builtin
@@ -113,7 +113,7 @@ impl CrateDefMap {
113 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes), 113 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes),
114 }; 114 };
115 log::debug!("resolving {:?} in crate root (+ extern prelude)", segment); 115 log::debug!("resolving {:?} in crate root (+ extern prelude)", segment);
116 self.resolve_name_in_crate_root_or_extern_prelude(&segment.name, prefer_module(idx)) 116 self.resolve_name_in_crate_root_or_extern_prelude(&segment, prefer_module(idx))
117 } 117 }
118 PathKind::Plain => { 118 PathKind::Plain => {
119 let (idx, segment) = match segments.next() { 119 let (idx, segment) = match segments.next() {
@@ -121,7 +121,7 @@ impl CrateDefMap {
121 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes), 121 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes),
122 }; 122 };
123 log::debug!("resolving {:?} in module", segment); 123 log::debug!("resolving {:?} in module", segment);
124 self.resolve_name_in_module(db, original_module, &segment.name, prefer_module(idx)) 124 self.resolve_name_in_module(db, original_module, &segment, prefer_module(idx))
125 } 125 }
126 PathKind::Super => { 126 PathKind::Super => {
127 if let Some(p) = self.modules[original_module].parent { 127 if let Some(p) = self.modules[original_module].parent {
@@ -137,7 +137,7 @@ impl CrateDefMap {
137 Some((_, segment)) => segment, 137 Some((_, segment)) => segment,
138 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes), 138 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes),
139 }; 139 };
140 if let Some(def) = self.extern_prelude.get(&segment.name) { 140 if let Some(def) = self.extern_prelude.get(&segment) {
141 log::debug!("absolute path {:?} resolved to crate {:?}", path, def); 141 log::debug!("absolute path {:?} resolved to crate {:?}", path, def);
142 PerNs::types(*def) 142 PerNs::types(*def)
143 } else { 143 } else {
@@ -168,8 +168,10 @@ impl CrateDefMap {
168 curr_per_ns = match curr { 168 curr_per_ns = match curr {
169 ModuleDefId::ModuleId(module) => { 169 ModuleDefId::ModuleId(module) => {
170 if module.krate != self.krate { 170 if module.krate != self.krate {
171 let path = 171 let path = ModPath {
172 Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ }; 172 segments: path.segments[i..].to_vec(),
173 kind: PathKind::Self_,
174 };
173 log::debug!("resolving {:?} in other crate", path); 175 log::debug!("resolving {:?} in other crate", path);
174 let defp_map = db.crate_def_map(module.krate); 176 let defp_map = db.crate_def_map(module.krate);
175 let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow); 177 let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow);
@@ -182,10 +184,10 @@ impl CrateDefMap {
182 } 184 }
183 185
184 // Since it is a qualified path here, it should not contains legacy macros 186 // Since it is a qualified path here, it should not contains legacy macros
185 match self[module.local_id].scope.get(&segment.name, prefer_module(i)) { 187 match self[module.local_id].scope.get(&segment, prefer_module(i)) {
186 Some(res) => res.def, 188 Some(res) => res.def,
187 _ => { 189 _ => {
188 log::debug!("path segment {:?} not found", segment.name); 190 log::debug!("path segment {:?} not found", segment);
189 return ResolvePathResult::empty(ReachedFixedPoint::No); 191 return ResolvePathResult::empty(ReachedFixedPoint::No);
190 } 192 }
191 } 193 }
@@ -194,7 +196,7 @@ impl CrateDefMap {
194 // enum variant 196 // enum variant
195 tested_by!(can_import_enum_variant); 197 tested_by!(can_import_enum_variant);
196 let enum_data = db.enum_data(e); 198 let enum_data = db.enum_data(e);
197 match enum_data.variant(&segment.name) { 199 match enum_data.variant(&segment) {
198 Some(local_id) => { 200 Some(local_id) => {
199 let variant = EnumVariantId { parent: e, local_id }; 201 let variant = EnumVariantId { parent: e, local_id };
200 PerNs::both(variant.into(), variant.into()) 202 PerNs::both(variant.into(), variant.into())
@@ -214,7 +216,7 @@ impl CrateDefMap {
214 // (`Struct::method`), or some other kind of associated item 216 // (`Struct::method`), or some other kind of associated item
215 log::debug!( 217 log::debug!(
216 "path segment {:?} resolved to non-module {:?}, but is not last", 218 "path segment {:?} resolved to non-module {:?}, but is not last",
217 segment.name, 219 segment,
218 curr, 220 curr,
219 ); 221 );
220 222