aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-31 20:04:07 +0000
committerGitHub <[email protected]>2021-01-31 20:04:07 +0000
commite6e93b3d1d8af018a6cb1fe3fd6c3f166c8a64f5 (patch)
tree20420c6ff4f67e09395700d4877e797cda865820
parent286d90de2d213b467a092e702edf8b0706c7c1b2 (diff)
parent412f180d71bb942dcda5afaa7d6dc2ad6f463d61 (diff)
Merge #7502
7502: Honor #![macro_use] in mod source files r=jonas-schievink a=Veykril Fixes #7501 Since `ItemTree` builds the `RawAttrs` directly we need the special check here as I don't think we can fix this in `RawAttrs` constructor as its solely AST based and we need to touch two different ASTs here. This just made me realize that `attrs_query` suffers from a similar problem, for example hovering an outline `mod` decl won't show inner docs, only outer ones, #7503. Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r--crates/hir_def/src/nameres/collector.rs17
-rw-r--r--crates/hir_def/src/nameres/tests/macros.rs14
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);
391mod m4; 391mod m4;
392bar!(OkMacroUse); 392bar!(OkMacroUse);
393 393
394mod m5;
395baz!(OkMacroUseInner);
396
394//- /m3/m4.rs 397//- /m3/m4.rs
395foo!(ok_shadow_deep); 398foo!(ok_shadow_deep);
396macro_rules! bar { 399macro_rules! bar {
397 ($x:ident) => { struct $x; } 400 ($x:ident) => { struct $x; }
398} 401}
402//- /m3/m5.rs
403#![macro_use]
404macro_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}