@@ -15,6 +15,7 @@ use rustc_middle::ty::{DefIdTree, Visibility};
15
15
use rustc_resolve:: { ParentScope , Resolver } ;
16
16
use rustc_session:: config:: Externs ;
17
17
use rustc_session:: Session ;
18
+ use rustc_span:: symbol:: sym;
18
19
use rustc_span:: { Symbol , SyntaxContext } ;
19
20
20
21
use std:: collections:: hash_map:: Entry ;
@@ -216,6 +217,8 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
216
217
ns : Namespace ,
217
218
parent_scope : & ParentScope < ' ra > ,
218
219
) -> bool {
220
+ // FIXME: This caching may be incorrect in case of multiple `macro_rules`
221
+ // items with the same name in the same module.
219
222
self . doc_link_resolutions
220
223
. entry ( ( Symbol :: intern ( path_str) , ns, parent_scope. module . def_id ( ) ) )
221
224
. or_insert_with_key ( |( path, ns, _) | {
@@ -307,18 +310,30 @@ impl Visitor<'_> for EarlyDocLinkResolver<'_, '_> {
307
310
let module_def_id = self . resolver . local_def_id ( item. id ) . to_def_id ( ) ;
308
311
let module = self . resolver . expect_module ( module_def_id) ;
309
312
let old_module = mem:: replace ( & mut self . parent_scope . module , module) ;
313
+ let old_macro_rules = self . parent_scope . macro_rules ;
310
314
self . resolve_doc_links_local ( & item. attrs ) ; // Inner attribute scope
311
315
self . process_module_children_or_reexports ( module_def_id) ;
312
316
visit:: walk_item ( self , item) ;
317
+ if item
318
+ . attrs
319
+ . iter ( )
320
+ . all ( |attr| !attr. has_name ( sym:: macro_use) && !attr. has_name ( sym:: macro_escape) )
321
+ {
322
+ self . parent_scope . macro_rules = old_macro_rules;
323
+ }
313
324
self . parent_scope . module = old_module;
314
325
} else {
315
- match item. kind {
326
+ match & item. kind {
316
327
ItemKind :: Trait ( ..) => {
317
328
self . all_traits . push ( self . resolver . local_def_id ( item. id ) . to_def_id ( ) ) ;
318
329
}
319
330
ItemKind :: Impl ( box ast:: Impl { of_trait : Some ( ..) , .. } ) => {
320
331
self . all_trait_impls . push ( self . resolver . local_def_id ( item. id ) . to_def_id ( ) ) ;
321
332
}
333
+ ItemKind :: MacroDef ( macro_def) if macro_def. macro_rules => {
334
+ self . parent_scope . macro_rules =
335
+ self . resolver . macro_rules_scope ( self . resolver . local_def_id ( item. id ) ) ;
336
+ }
322
337
_ => { }
323
338
}
324
339
visit:: walk_item ( self , item) ;
@@ -345,6 +360,12 @@ impl Visitor<'_> for EarlyDocLinkResolver<'_, '_> {
345
360
visit:: walk_field_def ( self , field)
346
361
}
347
362
363
+ fn visit_block ( & mut self , block : & ast:: Block ) {
364
+ let old_macro_rules = self . parent_scope . macro_rules ;
365
+ visit:: walk_block ( self , block) ;
366
+ self . parent_scope . macro_rules = old_macro_rules;
367
+ }
368
+
348
369
// NOTE: if doc-comments are ever allowed on other nodes (e.g. function parameters),
349
370
// then this will have to implement other visitor methods too.
350
371
}
0 commit comments