@@ -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,18 @@ 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) && !self . cx . tcx . is_doc_hidden ( src_def_id) {
1355
+ privacy_error ( self . cx , diag_info, path_str, PrivacyErrorKind :: Hidden ) ;
1351
1356
}
1352
1357
1353
1358
Some ( ( ) )
@@ -2334,8 +2339,20 @@ fn suggest_disambiguator(
2334
2339
}
2335
2340
}
2336
2341
2342
+ #[ derive( Copy , Clone ) ]
2343
+ enum PrivacyErrorKind {
2344
+ Private ,
2345
+ Hidden ,
2346
+ }
2347
+
2337
2348
/// Report a link from a public item to a private one.
2338
- fn privacy_error ( cx : & DocContext < ' _ > , diag_info : & DiagnosticInfo < ' _ > , path_str : & str ) {
2349
+ fn privacy_error (
2350
+ cx : & DocContext < ' _ > ,
2351
+ diag_info : & DiagnosticInfo < ' _ > ,
2352
+ path_str : & str ,
2353
+ kind : PrivacyErrorKind ,
2354
+ ) {
2355
+ use PrivacyErrorKind :: * ;
2339
2356
let sym;
2340
2357
let item_name = match diag_info. item . name {
2341
2358
Some ( name) => {
@@ -2344,17 +2361,22 @@ fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str:
2344
2361
}
2345
2362
None => "<unknown>" ,
2346
2363
} ;
2347
- let msg = format ! ( "public documentation for `{item_name}` links to private item `{path_str}`" ) ;
2364
+ let ( public, private, flag, lint) = match kind {
2365
+ Private => ( "public" , "private" , "--document-private-items" , PRIVATE_INTRA_DOC_LINKS ) ,
2366
+ Hidden => ( "non-hidden" , "hidden" , "--document-hidden-items" , HIDDEN_INTRA_DOC_LINKS ) ,
2367
+ } ;
2368
+ let msg =
2369
+ format ! ( "{public} documentation for `{item_name}` links to {private} item `{path_str}`" ) ;
2348
2370
2349
- report_diagnostic ( cx. tcx , PRIVATE_INTRA_DOC_LINKS , msg, diag_info, |diag, sp, _link_range| {
2371
+ report_diagnostic ( cx. tcx , lint , msg, diag_info, |diag, sp, _link_range| {
2350
2372
if let Some ( sp) = sp {
2351
- diag. span_label ( sp, "this item is private" ) ;
2373
+ diag. span_label ( sp, format ! ( "this item is { private}" ) ) ;
2352
2374
}
2353
2375
2354
2376
let note_msg = if cx. render_options . document_private {
2355
- "this link resolves only because you passed `--document-private-items `, but will break without"
2377
+ format ! ( "this link resolves only because you passed `{flag} `, but will break without" )
2356
2378
} else {
2357
- "this link will resolve properly if you pass `--document-private-items`"
2379
+ format ! ( "this link will resolve properly if you pass `{flag}`" )
2358
2380
} ;
2359
2381
diag. note ( note_msg) ;
2360
2382
} ) ;
0 commit comments