diff options
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 9 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 14 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests.rs | 13 |
3 files changed, 23 insertions, 13 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 6e86cc4a7..f904a97de 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1449,10 +1449,11 @@ impl ModCollector<'_, '_> { | |||
1449 | if let Some(macro_call_id) = | 1449 | if let Some(macro_call_id) = |
1450 | ast_id.as_call_id(self.def_collector.db, self.def_collector.def_map.krate, |path| { | 1450 | ast_id.as_call_id(self.def_collector.db, self.def_collector.def_map.krate, |path| { |
1451 | path.as_ident().and_then(|name| { | 1451 | path.as_ident().and_then(|name| { |
1452 | self.def_collector | 1452 | self.def_collector.def_map.with_ancestor_maps( |
1453 | .def_map | 1453 | self.def_collector.db, |
1454 | .ancestor_maps(self.module_id) | 1454 | self.module_id, |
1455 | .find_map(|(map, module)| map[module].scope.get_legacy_macro(&name)) | 1455 | &mut |map, module| map[module].scope.get_legacy_macro(&name), |
1456 | ) | ||
1456 | }) | 1457 | }) |
1457 | }) | 1458 | }) |
1458 | { | 1459 | { |
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index ecf75c777..2a3ac5d7b 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs | |||
@@ -110,6 +110,7 @@ impl DefMap { | |||
110 | let mut result = ResolvePathResult::empty(ReachedFixedPoint::No); | 110 | let mut result = ResolvePathResult::empty(ReachedFixedPoint::No); |
111 | result.segment_index = Some(usize::max_value()); | 111 | result.segment_index = Some(usize::max_value()); |
112 | 112 | ||
113 | let mut arc; | ||
113 | let mut current_map = self; | 114 | let mut current_map = self; |
114 | loop { | 115 | loop { |
115 | let new = current_map.resolve_path_fp_with_macro_single( | 116 | let new = current_map.resolve_path_fp_with_macro_single( |
@@ -131,8 +132,9 @@ impl DefMap { | |||
131 | 132 | ||
132 | match ¤t_map.block { | 133 | match ¤t_map.block { |
133 | Some(block) => { | 134 | Some(block) => { |
134 | current_map = &block.parent; | 135 | original_module = block.parent.local_id; |
135 | original_module = block.parent_module; | 136 | arc = block.parent.def_map(db); |
137 | current_map = &*arc; | ||
136 | } | 138 | } |
137 | None => return result, | 139 | None => return result, |
138 | } | 140 | } |
@@ -152,7 +154,7 @@ impl DefMap { | |||
152 | PathKind::DollarCrate(krate) => { | 154 | PathKind::DollarCrate(krate) => { |
153 | if krate == self.krate { | 155 | if krate == self.krate { |
154 | mark::hit!(macro_dollar_crate_self); | 156 | mark::hit!(macro_dollar_crate_self); |
155 | PerNs::types(self.crate_root().into(), Visibility::Public) | 157 | PerNs::types(self.crate_root(db).into(), Visibility::Public) |
156 | } else { | 158 | } else { |
157 | let def_map = db.crate_def_map(krate); | 159 | let def_map = db.crate_def_map(krate); |
158 | let module = def_map.module_id(def_map.root); | 160 | let module = def_map.module_id(def_map.root); |
@@ -160,7 +162,7 @@ impl DefMap { | |||
160 | PerNs::types(module.into(), Visibility::Public) | 162 | PerNs::types(module.into(), Visibility::Public) |
161 | } | 163 | } |
162 | } | 164 | } |
163 | PathKind::Crate => PerNs::types(self.crate_root().into(), Visibility::Public), | 165 | PathKind::Crate => PerNs::types(self.crate_root(db).into(), Visibility::Public), |
164 | // plain import or absolute path in 2015: crate-relative with | 166 | // plain import or absolute path in 2015: crate-relative with |
165 | // fallback to extern prelude (with the simplification in | 167 | // fallback to extern prelude (with the simplification in |
166 | // rust-lang/rust#57745) | 168 | // rust-lang/rust#57745) |
@@ -206,10 +208,10 @@ impl DefMap { | |||
206 | segments: path.segments.clone(), | 208 | segments: path.segments.clone(), |
207 | }; | 209 | }; |
208 | log::debug!("`super` path: {} -> {} in parent map", path, new_path); | 210 | log::debug!("`super` path: {} -> {} in parent map", path, new_path); |
209 | return block.parent.resolve_path_fp_with_macro( | 211 | return block.parent.def_map(db).resolve_path_fp_with_macro( |
210 | db, | 212 | db, |
211 | mode, | 213 | mode, |
212 | block.parent_module, | 214 | block.parent.local_id, |
213 | &new_path, | 215 | &new_path, |
214 | shadow, | 216 | shadow, |
215 | ); | 217 | ); |
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs index 723481c36..bd3e2701b 100644 --- a/crates/hir_def/src/nameres/tests.rs +++ b/crates/hir_def/src/nameres/tests.rs | |||
@@ -11,7 +11,9 @@ use base_db::{fixture::WithFixture, SourceDatabase}; | |||
11 | use expect_test::{expect, Expect}; | 11 | use expect_test::{expect, Expect}; |
12 | use test_utils::mark; | 12 | use test_utils::mark; |
13 | 13 | ||
14 | use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; | 14 | use crate::{db::DefDatabase, test_db::TestDB}; |
15 | |||
16 | use super::DefMap; | ||
15 | 17 | ||
16 | fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> { | 18 | fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> { |
17 | let db = TestDB::with_files(ra_fixture); | 19 | let db = TestDB::with_files(ra_fixture); |
@@ -19,9 +21,14 @@ fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> { | |||
19 | db.crate_def_map(krate) | 21 | db.crate_def_map(krate) |
20 | } | 22 | } |
21 | 23 | ||
24 | fn render_crate_def_map(ra_fixture: &str) -> String { | ||
25 | let db = TestDB::with_files(ra_fixture); | ||
26 | let krate = db.crate_graph().iter().next().unwrap(); | ||
27 | db.crate_def_map(krate).dump(&db) | ||
28 | } | ||
29 | |||
22 | fn check(ra_fixture: &str, expect: Expect) { | 30 | fn check(ra_fixture: &str, expect: Expect) { |
23 | let def_map = compute_crate_def_map(ra_fixture); | 31 | let actual = render_crate_def_map(ra_fixture); |
24 | let actual = def_map.dump(); | ||
25 | expect.assert_eq(&actual); | 32 | expect.assert_eq(&actual); |
26 | } | 33 | } |
27 | 34 | ||