@@ -443,21 +443,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
443443 } )
444444 }
445445
446- /// HACK: Try to search the macro name in the list of all `macro_rules` items in the crate.
447- /// Used when nothing else works, may often give an incorrect result.
448- fn resolve_macro_rules ( & self , path_str : & str , ns : Namespace ) -> Option < Res > {
449- if ns != MacroNS {
450- return None ;
451- }
452-
453- self . cx
454- . resolver_caches
455- . all_macro_rules
456- . get ( & Symbol :: intern ( path_str) )
457- . copied ( )
458- . and_then ( |res| res. try_into ( ) . ok ( ) )
459- }
460-
461446 /// Convenience wrapper around `resolve_rustdoc_path`.
462447 ///
463448 /// This also handles resolving `true` and `false` as booleans.
@@ -489,8 +474,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
489474 } )
490475 } )
491476 . and_then ( |res| res. try_into ( ) . ok ( ) )
492- . or_else ( || resolve_primitive ( path_str, ns) )
493- . or_else ( || self . resolve_macro_rules ( path_str, ns) ) ;
477+ . or_else ( || resolve_primitive ( path_str, ns) ) ;
494478 debug ! ( "{} resolved to {:?} in namespace {:?}" , path_str, result, ns) ;
495479 result
496480 }
@@ -1391,11 +1375,7 @@ impl LinkCollector<'_, '_> {
13911375 }
13921376 }
13931377 }
1394- resolution_failure ( self , diag, path_str, disambiguator, smallvec ! [ err] ) ;
1395- // This could just be a normal link or a broken link
1396- // we could potentially check if something is
1397- // "intra-doc-link-like" and warn in that case.
1398- None
1378+ resolution_failure ( self , diag, path_str, disambiguator, smallvec ! [ err] )
13991379 }
14001380 }
14011381 }
@@ -1423,15 +1403,13 @@ impl LinkCollector<'_, '_> {
14231403 let len = candidates. iter ( ) . filter ( |res| res. is_ok ( ) ) . count ( ) ;
14241404
14251405 if len == 0 {
1426- resolution_failure (
1406+ return resolution_failure (
14271407 self ,
14281408 diag,
14291409 path_str,
14301410 disambiguator,
14311411 candidates. into_iter ( ) . filter_map ( |res| res. err ( ) ) . collect ( ) ,
14321412 ) ;
1433- // this could just be a normal link
1434- return None ;
14351413 }
14361414
14371415 if len == 1 {
@@ -1737,8 +1715,9 @@ fn resolution_failure(
17371715 path_str : & str ,
17381716 disambiguator : Option < Disambiguator > ,
17391717 kinds : SmallVec < [ ResolutionFailure < ' _ > ; 3 ] > ,
1740- ) {
1718+ ) -> Option < ( Res , Option < DefId > ) > {
17411719 let tcx = collector. cx . tcx ;
1720+ let mut recovered_res = None ;
17421721 report_diagnostic (
17431722 tcx,
17441723 BROKEN_INTRA_DOC_LINKS ,
@@ -1826,11 +1805,22 @@ fn resolution_failure(
18261805 diag. note ( & note) ;
18271806 }
18281807
1829- // If the link has `::` in it, assume it was meant to be an intra-doc link.
1830- // Otherwise, the `[]` might be unrelated.
1831- // FIXME: don't show this for autolinks (`<>`), `()` style links, or reference links
18321808 if !path_str. contains ( "::" ) {
1833- diag. help ( r#"to escape `[` and `]` characters, add '\' before them like `\[` or `\]`"# ) ;
1809+ if disambiguator. map_or ( true , |d| d. ns ( ) == MacroNS )
1810+ && let Some ( & res) = collector. cx . resolver_caches . all_macro_rules
1811+ . get ( & Symbol :: intern ( path_str) )
1812+ {
1813+ diag. note ( format ! (
1814+ "`macro_rules` named `{path_str}` exists in this crate, \
1815+ but it is not in scope at this link's location"
1816+ ) ) ;
1817+ recovered_res = res. try_into ( ) . ok ( ) . map ( |res| ( res, None ) ) ;
1818+ } else {
1819+ // If the link has `::` in it, assume it was meant to be an
1820+ // intra-doc link. Otherwise, the `[]` might be unrelated.
1821+ diag. help ( "to escape `[` and `]` characters, \
1822+ add '\\ ' before them like `\\ [` or `\\ ]`") ;
1823+ }
18341824 }
18351825
18361826 continue ;
@@ -1915,6 +1905,8 @@ fn resolution_failure(
19151905 }
19161906 } ,
19171907 ) ;
1908+
1909+ recovered_res
19181910}
19191911
19201912fn report_multiple_anchors ( cx : & DocContext < ' _ > , diag_info : DiagnosticInfo < ' _ > ) {
0 commit comments