@@ -11,7 +11,10 @@ use rustc_hir::def::{
1111use rustc_hir:: def_id:: DefId ;
1212use rustc_middle:: ty;
1313use 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+ } ;
1518use rustc_span:: hygiene:: MacroKind ;
1619use rustc_span:: symbol:: Ident ;
1720use rustc_span:: symbol:: Symbol ;
@@ -988,7 +991,7 @@ impl LinkCollector<'_, '_> {
988991 let report_mismatch = |specified : Disambiguator , resolved : Disambiguator | {
989992 // The resolved item did not match the disambiguator; give a better error than 'not found'
990993 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| {
992995 let note = format ! (
993996 "this link resolved to {} {}, which is not {} {}" ,
994997 resolved. article( ) ,
@@ -998,7 +1001,8 @@ impl LinkCollector<'_, '_> {
9981001 ) ;
9991002 diag. note ( & note) ;
10001003 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) ;
10021006 } ;
10031007 if let Res :: PrimTy ( ..) = res {
10041008 match disambiguator {
@@ -1055,7 +1059,6 @@ impl LinkCollector<'_, '_> {
10551059 && !self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_dst)
10561060 {
10571061 privacy_error ( cx, & item, & path_str, dox, link_range) ;
1058- return ;
10591062 }
10601063 }
10611064 let id = register_res ( cx, res) ;
@@ -1417,6 +1420,7 @@ impl Suggestion {
14171420/// to it.
14181421fn report_diagnostic (
14191422 cx : & DocContext < ' _ > ,
1423+ lint : & ' static Lint ,
14201424 msg : & str ,
14211425 item : & Item ,
14221426 dox : & str ,
@@ -1435,7 +1439,7 @@ fn report_diagnostic(
14351439 let attrs = & item. attrs ;
14361440 let sp = span_of_attrs ( attrs) . unwrap_or ( item. source . span ( ) ) ;
14371441
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| {
14391443 let mut diag = lint. build ( msg) ;
14401444
14411445 let span = link_range
@@ -1482,6 +1486,7 @@ fn resolution_failure(
14821486) {
14831487 report_diagnostic (
14841488 collector. cx ,
1489+ BROKEN_INTRA_DOC_LINKS ,
14851490 & format ! ( "unresolved link to `{}`" , path_str) ,
14861491 item,
14871492 dox,
@@ -1695,7 +1700,7 @@ fn anchor_failure(
16951700 ) ,
16961701 } ;
16971702
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| {
16991704 if let Some ( sp) = sp {
17001705 diag. span_label ( sp, "contains invalid anchor" ) ;
17011706 }
@@ -1734,7 +1739,7 @@ fn ambiguity_error(
17341739 }
17351740 }
17361741
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| {
17381743 if let Some ( sp) = sp {
17391744 diag. span_label ( sp, "ambiguous link" ) ;
17401745 } else {
@@ -1784,7 +1789,7 @@ fn privacy_error(
17841789 let msg =
17851790 format ! ( "public documentation for `{}` links to private item `{}`" , item_name, path_str) ;
17861791
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| {
17881793 if let Some ( sp) = sp {
17891794 diag. span_label ( sp, "this item is private" ) ;
17901795 }
0 commit comments