@@ -11,7 +11,10 @@ use rustc_hir::def::{
11
11
use rustc_hir:: def_id:: DefId ;
12
12
use rustc_middle:: ty;
13
13
use rustc_resolve:: ParentScope ;
14
- use rustc_session:: lint;
14
+ use rustc_session:: lint:: {
15
+ builtin:: { BROKEN_INTRA_DOC_LINKS , PRIVATE_INTRA_DOC_LINKS } ,
16
+ Lint ,
17
+ } ;
15
18
use rustc_span:: hygiene:: MacroKind ;
16
19
use rustc_span:: symbol:: Ident ;
17
20
use rustc_span:: symbol:: Symbol ;
@@ -988,7 +991,7 @@ impl LinkCollector<'_, '_> {
988
991
let report_mismatch = |specified : Disambiguator , resolved : Disambiguator | {
989
992
// The resolved item did not match the disambiguator; give a better error than 'not found'
990
993
let msg = format ! ( "incompatible link kind for `{}`" , path_str) ;
991
- report_diagnostic ( cx , & msg , & item , dox , & link_range , |diag , sp| {
994
+ let callback = | diag : & mut DiagnosticBuilder < ' _ > , sp| {
992
995
let note = format ! (
993
996
"this link resolved to {} {}, which is not {} {}" ,
994
997
resolved. article( ) ,
@@ -998,7 +1001,8 @@ impl LinkCollector<'_, '_> {
998
1001
) ;
999
1002
diag. note ( & note) ;
1000
1003
suggest_disambiguator ( resolved, diag, path_str, dox, sp, & link_range) ;
1001
- } ) ;
1004
+ } ;
1005
+ report_diagnostic ( cx, BROKEN_INTRA_DOC_LINKS , & msg, & item, dox, & link_range, callback) ;
1002
1006
} ;
1003
1007
if let Res :: PrimTy ( ..) = res {
1004
1008
match disambiguator {
@@ -1055,7 +1059,6 @@ impl LinkCollector<'_, '_> {
1055
1059
&& !self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_dst)
1056
1060
{
1057
1061
privacy_error ( cx, & item, & path_str, dox, link_range) ;
1058
- return ;
1059
1062
}
1060
1063
}
1061
1064
let id = register_res ( cx, res) ;
@@ -1417,6 +1420,7 @@ impl Suggestion {
1417
1420
/// to it.
1418
1421
fn report_diagnostic (
1419
1422
cx : & DocContext < ' _ > ,
1423
+ lint : & ' static Lint ,
1420
1424
msg : & str ,
1421
1425
item : & Item ,
1422
1426
dox : & str ,
@@ -1435,7 +1439,7 @@ fn report_diagnostic(
1435
1439
let attrs = & item. attrs ;
1436
1440
let sp = span_of_attrs ( attrs) . unwrap_or ( item. source . span ( ) ) ;
1437
1441
1438
- cx. tcx . struct_span_lint_hir ( lint:: builtin :: BROKEN_INTRA_DOC_LINKS , hir_id, sp, |lint| {
1442
+ cx. tcx . struct_span_lint_hir ( lint, hir_id, sp, |lint| {
1439
1443
let mut diag = lint. build ( msg) ;
1440
1444
1441
1445
let span = link_range
@@ -1482,6 +1486,7 @@ fn resolution_failure(
1482
1486
) {
1483
1487
report_diagnostic (
1484
1488
collector. cx ,
1489
+ BROKEN_INTRA_DOC_LINKS ,
1485
1490
& format ! ( "unresolved link to `{}`" , path_str) ,
1486
1491
item,
1487
1492
dox,
@@ -1695,7 +1700,7 @@ fn anchor_failure(
1695
1700
) ,
1696
1701
} ;
1697
1702
1698
- report_diagnostic ( cx, & msg, item, dox, & link_range, |diag, sp| {
1703
+ report_diagnostic ( cx, BROKEN_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
1699
1704
if let Some ( sp) = sp {
1700
1705
diag. span_label ( sp, "contains invalid anchor" ) ;
1701
1706
}
@@ -1734,7 +1739,7 @@ fn ambiguity_error(
1734
1739
}
1735
1740
}
1736
1741
1737
- report_diagnostic ( cx, & msg, item, dox, & link_range, |diag, sp| {
1742
+ report_diagnostic ( cx, BROKEN_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
1738
1743
if let Some ( sp) = sp {
1739
1744
diag. span_label ( sp, "ambiguous link" ) ;
1740
1745
} else {
@@ -1784,7 +1789,7 @@ fn privacy_error(
1784
1789
let msg =
1785
1790
format ! ( "public documentation for `{}` links to private item `{}`" , item_name, path_str) ;
1786
1791
1787
- report_diagnostic ( cx, & msg, item, dox, & link_range, |diag, sp| {
1792
+ report_diagnostic ( cx, PRIVATE_INTRA_DOC_LINKS , & msg, item, dox, & link_range, |diag, sp| {
1788
1793
if let Some ( sp) = sp {
1789
1794
diag. span_label ( sp, "this item is private" ) ;
1790
1795
}
0 commit comments