@@ -443,21 +443,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
443
443
})
444
444
}
445
445
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
-
461
446
/// Convenience wrapper around `resolve_rustdoc_path`.
462
447
///
463
448
/// This also handles resolving `true` and `false` as booleans.
@@ -489,8 +474,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
489
474
})
490
475
})
491
476
.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));
494
478
debug!("{} resolved to {:?} in namespace {:?}", path_str, result, ns);
495
479
result
496
480
}
@@ -1391,11 +1375,7 @@ impl LinkCollector<'_, '_> {
1391
1375
}
1392
1376
}
1393
1377
}
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])
1399
1379
}
1400
1380
}
1401
1381
}
@@ -1423,15 +1403,13 @@ impl LinkCollector<'_, '_> {
1423
1403
let len = candidates.iter().filter(|res| res.is_ok()).count();
1424
1404
1425
1405
if len == 0 {
1426
- resolution_failure(
1406
+ return resolution_failure(
1427
1407
self,
1428
1408
diag,
1429
1409
path_str,
1430
1410
disambiguator,
1431
1411
candidates.into_iter().filter_map(|res| res.err()).collect(),
1432
1412
);
1433
- // this could just be a normal link
1434
- return None;
1435
1413
}
1436
1414
1437
1415
if len == 1 {
@@ -1737,8 +1715,9 @@ fn resolution_failure(
1737
1715
path_str: &str,
1738
1716
disambiguator: Option<Disambiguator>,
1739
1717
kinds: SmallVec<[ResolutionFailure<'_>; 3]>,
1740
- ) {
1718
+ ) -> Option<(Res, Option<DefId>)> {
1741
1719
let tcx = collector.cx.tcx;
1720
+ let mut recovered_res = None;
1742
1721
report_diagnostic(
1743
1722
tcx,
1744
1723
BROKEN_INTRA_DOC_LINKS,
@@ -1826,11 +1805,22 @@ fn resolution_failure(
1826
1805
diag.note(¬e);
1827
1806
}
1828
1807
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
1832
1808
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
+ }
1834
1824
}
1835
1825
1836
1826
continue;
@@ -1915,6 +1905,8 @@ fn resolution_failure(
1915
1905
}
1916
1906
},
1917
1907
);
1908
+
1909
+ recovered_res
1918
1910
}
1919
1911
1920
1912
fn report_multiple_anchors(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>) {
0 commit comments