@@ -122,6 +122,42 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
122
122
}
123
123
}
124
124
125
+ /// Resolves a string as a macro.
126
+ fn macro_resolve ( & self , path_str : & str , parent_id : Option < hir:: HirId > ) -> Option < Res > {
127
+ let cx = self . cx ;
128
+ let path = ast:: Path :: from_ident ( Ident :: from_str ( path_str) ) ;
129
+ cx. enter_resolver ( |resolver| {
130
+ if let Ok ( ( Some ( ext) , res) ) = resolver. resolve_macro_path (
131
+ & path,
132
+ None ,
133
+ & ParentScope :: module ( resolver. graph_root ( ) ) ,
134
+ false ,
135
+ false ,
136
+ ) {
137
+ if let SyntaxExtensionKind :: LegacyBang { .. } = ext. kind {
138
+ return Some ( res. map_id ( |_| panic ! ( "unexpected id" ) ) ) ;
139
+ }
140
+ }
141
+ if let Some ( res) = resolver. all_macros ( ) . get ( & Symbol :: intern ( path_str) ) {
142
+ return Some ( res. map_id ( |_| panic ! ( "unexpected id" ) ) ) ;
143
+ }
144
+ if let Some ( module_id) = parent_id. or ( self . mod_ids . last ( ) . cloned ( ) ) {
145
+ let module_id = cx. tcx . hir ( ) . local_def_id ( module_id) ;
146
+ if let Ok ( ( _, res) ) =
147
+ resolver. resolve_str_path_error ( DUMMY_SP , path_str, MacroNS , module_id)
148
+ {
149
+ // don't resolve builtins like `#[derive]`
150
+ if let Res :: Def ( ..) = res {
151
+ let res = res. map_id ( |_| panic ! ( "unexpected node_id" ) ) ;
152
+ return Some ( res) ;
153
+ }
154
+ }
155
+ } else {
156
+ debug ! ( "attempting to resolve item without parent module: {}" , path_str) ;
157
+ }
158
+ None
159
+ } )
160
+ }
125
161
/// Resolves a string as a path within a particular namespace. Also returns an optional
126
162
/// URL fragment in the case of variants and methods.
127
163
fn resolve (
@@ -615,7 +651,8 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
615
651
None => {
616
652
// Try everything!
617
653
let candidates = PerNS {
618
- macro_ns : macro_resolve ( cx, path_str)
654
+ macro_ns : self
655
+ . macro_resolve ( path_str, base_node)
619
656
. map ( |res| ( res, extra_fragment. clone ( ) ) ) ,
620
657
type_ns : match self . resolve (
621
658
path_str,
@@ -684,7 +721,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
684
721
}
685
722
}
686
723
Some ( MacroNS ) => {
687
- if let Some ( res) = macro_resolve ( cx , path_str ) {
724
+ if let Some ( res) = self . macro_resolve ( path_str , base_node ) {
688
725
( res, extra_fragment)
689
726
} else {
690
727
resolution_failure ( cx, & item, path_str, & dox, link_range) ;
@@ -727,28 +764,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
727
764
}
728
765
}
729
766
730
- /// Resolves a string as a macro.
731
- fn macro_resolve ( cx : & DocContext < ' _ > , path_str : & str ) -> Option < Res > {
732
- let path = ast:: Path :: from_ident ( Ident :: from_str ( path_str) ) ;
733
- cx. enter_resolver ( |resolver| {
734
- if let Ok ( ( Some ( ext) , res) ) = resolver. resolve_macro_path (
735
- & path,
736
- None ,
737
- & ParentScope :: module ( resolver. graph_root ( ) ) ,
738
- false ,
739
- false ,
740
- ) {
741
- if let SyntaxExtensionKind :: LegacyBang { .. } = ext. kind {
742
- return Some ( res. map_id ( |_| panic ! ( "unexpected id" ) ) ) ;
743
- }
744
- }
745
- if let Some ( res) = resolver. all_macros ( ) . get ( & Symbol :: intern ( path_str) ) {
746
- return Some ( res. map_id ( |_| panic ! ( "unexpected id" ) ) ) ;
747
- }
748
- None
749
- } )
750
- }
751
-
752
767
fn build_diagnostic (
753
768
cx : & DocContext < ' _ > ,
754
769
item : & Item ,
0 commit comments