@@ -34,7 +34,7 @@ use crate::clean::utils::find_nearest_parent_module;
34
34
use crate :: clean:: { self , Crate , Item , ItemId , ItemLink , PrimitiveType } ;
35
35
use crate :: core:: DocContext ;
36
36
use crate :: html:: markdown:: { MarkdownLink , MarkdownLinkRange , markdown_links} ;
37
- use crate :: lint:: { BROKEN_INTRA_DOC_LINKS , PRIVATE_INTRA_DOC_LINKS } ;
37
+ use crate :: lint:: { BROKEN_INTRA_DOC_LINKS , HIDDEN_INTRA_DOC_LINKS , PRIVATE_INTRA_DOC_LINKS } ;
38
38
use crate :: passes:: Pass ;
39
39
use crate :: visit:: DocVisitor ;
40
40
@@ -1341,13 +1341,20 @@ impl LinkCollector<'_, '_> {
1341
1341
}
1342
1342
}
1343
1343
1344
+ let src_def_id = diag_info. item . item_id . expect_def_id ( ) ;
1344
1345
// item can be non-local e.g. when using `#[rustc_doc_primitive = "pointer"]`
1345
1346
if let Some ( dst_id) = id. as_local ( )
1346
- && let Some ( src_id) = diag_info . item . item_id . expect_def_id ( ) . as_local ( )
1347
+ && let Some ( src_id) = src_def_id . as_local ( )
1347
1348
&& self . cx . tcx . effective_visibilities ( ( ) ) . is_exported ( src_id)
1348
1349
&& !self . cx . tcx . effective_visibilities ( ( ) ) . is_exported ( dst_id)
1349
1350
{
1350
- privacy_error ( self . cx , diag_info, path_str) ;
1351
+ privacy_error ( self . cx , diag_info, path_str, PrivacyErrorKind :: Private ) ;
1352
+ }
1353
+
1354
+ if self . cx . tcx . is_doc_hidden ( id)
1355
+ && !self . cx . tcx . is_doc_hidden ( src_def_id)
1356
+ {
1357
+ privacy_error ( self . cx , diag_info, path_str, PrivacyErrorKind :: Hidden ) ;
1351
1358
}
1352
1359
1353
1360
Some ( ( ) )
@@ -2334,8 +2341,15 @@ fn suggest_disambiguator(
2334
2341
}
2335
2342
}
2336
2343
2344
+ #[ derive( Copy , Clone ) ]
2345
+ enum PrivacyErrorKind {
2346
+ Private ,
2347
+ Hidden ,
2348
+ }
2349
+
2337
2350
/// Report a link from a public item to a private one.
2338
- fn privacy_error ( cx : & DocContext < ' _ > , diag_info : & DiagnosticInfo < ' _ > , path_str : & str ) {
2351
+ fn privacy_error ( cx : & DocContext < ' _ > , diag_info : & DiagnosticInfo < ' _ > , path_str : & str , kind : PrivacyErrorKind ) {
2352
+ use PrivacyErrorKind :: * ;
2339
2353
let sym;
2340
2354
let item_name = match diag_info. item . name {
2341
2355
Some ( name) => {
@@ -2344,17 +2358,21 @@ fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str:
2344
2358
}
2345
2359
None => "<unknown>" ,
2346
2360
} ;
2347
- let msg = format ! ( "public documentation for `{item_name}` links to private item `{path_str}`" ) ;
2361
+ let ( public, private, flag, lint) = match kind {
2362
+ Private => ( "public" , "private" , "--document-private-items" , PRIVATE_INTRA_DOC_LINKS ) ,
2363
+ Hidden => ( "non-hidden" , "hidden" , "--document-hidden-items" , HIDDEN_INTRA_DOC_LINKS ) ,
2364
+ } ;
2365
+ let msg = format ! ( "{public} documentation for `{item_name}` links to {private} item `{path_str}`" ) ;
2348
2366
2349
- report_diagnostic ( cx. tcx , PRIVATE_INTRA_DOC_LINKS , msg, diag_info, |diag, sp, _link_range| {
2367
+ report_diagnostic ( cx. tcx , lint , msg, diag_info, |diag, sp, _link_range| {
2350
2368
if let Some ( sp) = sp {
2351
- diag. span_label ( sp, "this item is private" ) ;
2369
+ diag. span_label ( sp, format ! ( "this item is { private}" ) ) ;
2352
2370
}
2353
2371
2354
2372
let note_msg = if cx. render_options . document_private {
2355
- "this link resolves only because you passed `--document-private-items `, but will break without"
2373
+ format ! ( "this link resolves only because you passed `{flag} `, but will break without" )
2356
2374
} else {
2357
- "this link will resolve properly if you pass `--document-private-items`"
2375
+ format ! ( "this link will resolve properly if you pass `{flag}`" )
2358
2376
} ;
2359
2377
diag. note ( note_msg) ;
2360
2378
} ) ;
0 commit comments