diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-08 19:41:35 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-08 19:41:35 +0100 |
commit | 9c92c05ca614fcded456153b1bc6717d17f0dafb (patch) | |
tree | 4cdbfe1ae67d0eae6ba85b19cf40126898f43ac5 /crates/ra_hir/src/nameres.rs | |
parent | bb55111c209a9d3a6249cab35308a506b7f22d53 (diff) | |
parent | caefa6982bc57195687de11137997f1d62d791fe (diff) |
Merge #1386
1386: Remove one of the two different algorithms for name resolution of macros :D r=edwin0cheng a=matklad
r? @edwin0cheng
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index dc0dd23c9..b5938fa03 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -92,7 +92,6 @@ pub struct CrateDefMap { | |||
92 | extern_prelude: FxHashMap<Name, ModuleDef>, | 92 | extern_prelude: FxHashMap<Name, ModuleDef>, |
93 | root: CrateModuleId, | 93 | root: CrateModuleId, |
94 | modules: Arena<CrateModuleId, ModuleData>, | 94 | modules: Arena<CrateModuleId, ModuleData>, |
95 | public_macros: FxHashMap<Name, MacroDefId>, | ||
96 | 95 | ||
97 | /// Some macros are not well-behavior, which leads to infinite loop | 96 | /// Some macros are not well-behavior, which leads to infinite loop |
98 | /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } | 97 | /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } |
@@ -106,7 +105,6 @@ pub struct CrateDefMap { | |||
106 | /// However, do we want to put it as a global variable? | 105 | /// However, do we want to put it as a global variable? |
107 | poison_macros: FxHashSet<MacroDefId>, | 106 | poison_macros: FxHashSet<MacroDefId>, |
108 | 107 | ||
109 | local_macros: FxHashMap<Name, MacroDefId>, | ||
110 | diagnostics: Vec<DefDiagnostic>, | 108 | diagnostics: Vec<DefDiagnostic>, |
111 | } | 109 | } |
112 | 110 | ||
@@ -249,9 +247,7 @@ impl CrateDefMap { | |||
249 | prelude: None, | 247 | prelude: None, |
250 | root, | 248 | root, |
251 | modules, | 249 | modules, |
252 | public_macros: FxHashMap::default(), | ||
253 | poison_macros: FxHashSet::default(), | 250 | poison_macros: FxHashSet::default(), |
254 | local_macros: FxHashMap::default(), | ||
255 | diagnostics: Vec::new(), | 251 | diagnostics: Vec::new(), |
256 | } | 252 | } |
257 | }; | 253 | }; |
@@ -313,7 +309,7 @@ impl CrateDefMap { | |||
313 | (res.resolved_def.left().unwrap_or_else(PerNs::none), res.segment_index) | 309 | (res.resolved_def.left().unwrap_or_else(PerNs::none), res.segment_index) |
314 | } | 310 | } |
315 | 311 | ||
316 | fn resolve_path_with_macro( | 312 | pub(crate) fn resolve_path_with_macro( |
317 | &self, | 313 | &self, |
318 | db: &impl DefDatabase, | 314 | db: &impl DefDatabase, |
319 | original_module: CrateModuleId, | 315 | original_module: CrateModuleId, |
@@ -323,27 +319,6 @@ impl CrateDefMap { | |||
323 | (res.resolved_def, res.segment_index) | 319 | (res.resolved_def, res.segment_index) |
324 | } | 320 | } |
325 | 321 | ||
326 | // FIXME: This seems to do the same work as `resolve_path_with_macro`, but | ||
327 | // using a completely different code path. Seems bad, huh? | ||
328 | pub(crate) fn find_macro( | ||
329 | &self, | ||
330 | db: &impl DefDatabase, | ||
331 | original_module: CrateModuleId, | ||
332 | path: &Path, | ||
333 | ) -> Option<MacroDefId> { | ||
334 | let name = path.expand_macro_expr()?; | ||
335 | // search local first | ||
336 | // FIXME: Remove public_macros check when we have a correct local_macors implementation | ||
337 | let local = | ||
338 | self.public_macros.get(&name).or_else(|| self.local_macros.get(&name)).map(|it| *it); | ||
339 | if local.is_some() { | ||
340 | return local; | ||
341 | } | ||
342 | |||
343 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); | ||
344 | res.resolved_def.right().map(|m| m.id) | ||
345 | } | ||
346 | |||
347 | // Returns Yes if we are sure that additions to `ItemMap` wouldn't change | 322 | // Returns Yes if we are sure that additions to `ItemMap` wouldn't change |
348 | // the result. | 323 | // the result. |
349 | fn resolve_path_fp_with_macro( | 324 | fn resolve_path_fp_with_macro( |
@@ -511,7 +486,7 @@ impl CrateDefMap { | |||
511 | let from_scope = self[module] | 486 | let from_scope = self[module] |
512 | .scope | 487 | .scope |
513 | .get_item_or_macro(name) | 488 | .get_item_or_macro(name) |
514 | .unwrap_or_else(|| Either::Left(PerNs::none()));; | 489 | .unwrap_or_else(|| Either::Left(PerNs::none())); |
515 | let from_extern_prelude = | 490 | let from_extern_prelude = |
516 | self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); | 491 | self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); |
517 | let from_prelude = self.resolve_in_prelude(db, name); | 492 | let from_prelude = self.resolve_in_prelude(db, name); |