diff options
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 17 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/macros.rs | 14 |
2 files changed, 23 insertions, 8 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index ae98fadac..fcc8e2607 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1273,12 +1273,8 @@ impl ModCollector<'_, '_> { | |||
1273 | // out of line module, resolve, parse and recurse | 1273 | // out of line module, resolve, parse and recurse |
1274 | ModKind::Outline {} => { | 1274 | ModKind::Outline {} => { |
1275 | let ast_id = AstId::new(self.file_id, module.ast_id); | 1275 | let ast_id = AstId::new(self.file_id, module.ast_id); |
1276 | match self.mod_dir.resolve_declaration( | 1276 | let db = self.def_collector.db; |
1277 | self.def_collector.db, | 1277 | match self.mod_dir.resolve_declaration(db, self.file_id, &module.name, path_attr) { |
1278 | self.file_id, | ||
1279 | &module.name, | ||
1280 | path_attr, | ||
1281 | ) { | ||
1282 | Ok((file_id, is_mod_rs, mod_dir)) => { | 1278 | Ok((file_id, is_mod_rs, mod_dir)) => { |
1283 | let module_id = self.push_child_module( | 1279 | let module_id = self.push_child_module( |
1284 | module.name.clone(), | 1280 | module.name.clone(), |
@@ -1286,7 +1282,7 @@ impl ModCollector<'_, '_> { | |||
1286 | Some((file_id, is_mod_rs)), | 1282 | Some((file_id, is_mod_rs)), |
1287 | &self.item_tree[module.visibility], | 1283 | &self.item_tree[module.visibility], |
1288 | ); | 1284 | ); |
1289 | let item_tree = self.def_collector.db.item_tree(file_id.into()); | 1285 | let item_tree = db.item_tree(file_id.into()); |
1290 | ModCollector { | 1286 | ModCollector { |
1291 | def_collector: &mut *self.def_collector, | 1287 | def_collector: &mut *self.def_collector, |
1292 | macro_depth: self.macro_depth, | 1288 | macro_depth: self.macro_depth, |
@@ -1296,7 +1292,12 @@ impl ModCollector<'_, '_> { | |||
1296 | mod_dir, | 1292 | mod_dir, |
1297 | } | 1293 | } |
1298 | .collect(item_tree.top_level_items()); | 1294 | .collect(item_tree.top_level_items()); |
1299 | if is_macro_use { | 1295 | if is_macro_use |
1296 | || item_tree | ||
1297 | .top_level_attrs(db, self.def_collector.def_map.krate) | ||
1298 | .by_key("macro_use") | ||
1299 | .exists() | ||
1300 | { | ||
1300 | self.import_all_legacy_macros(module_id); | 1301 | self.import_all_legacy_macros(module_id); |
1301 | } | 1302 | } |
1302 | } | 1303 | } |
diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index e5e9e8ca1..36ed5e8ce 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs | |||
@@ -391,11 +391,21 @@ foo!(ok_shadow); | |||
391 | mod m4; | 391 | mod m4; |
392 | bar!(OkMacroUse); | 392 | bar!(OkMacroUse); |
393 | 393 | ||
394 | mod m5; | ||
395 | baz!(OkMacroUseInner); | ||
396 | |||
394 | //- /m3/m4.rs | 397 | //- /m3/m4.rs |
395 | foo!(ok_shadow_deep); | 398 | foo!(ok_shadow_deep); |
396 | macro_rules! bar { | 399 | macro_rules! bar { |
397 | ($x:ident) => { struct $x; } | 400 | ($x:ident) => { struct $x; } |
398 | } | 401 | } |
402 | //- /m3/m5.rs | ||
403 | #![macro_use] | ||
404 | macro_rules! baz { | ||
405 | ($x:ident) => { struct $x; } | ||
406 | } | ||
407 | |||
408 | |||
399 | "#, | 409 | "#, |
400 | expect![[r#" | 410 | expect![[r#" |
401 | crate | 411 | crate |
@@ -423,11 +433,15 @@ macro_rules! bar { | |||
423 | crate::m3 | 433 | crate::m3 |
424 | OkAfterInside: t v | 434 | OkAfterInside: t v |
425 | OkMacroUse: t v | 435 | OkMacroUse: t v |
436 | OkMacroUseInner: t v | ||
426 | m4: t | 437 | m4: t |
438 | m5: t | ||
427 | ok_shadow: v | 439 | ok_shadow: v |
428 | 440 | ||
429 | crate::m3::m4 | 441 | crate::m3::m4 |
430 | ok_shadow_deep: v | 442 | ok_shadow_deep: v |
443 | |||
444 | crate::m3::m5 | ||
431 | "#]], | 445 | "#]], |
432 | ); | 446 | ); |
433 | } | 447 | } |