@@ -14,6 +14,7 @@ use rustc_hir::Mutability;
14
14
use rustc_metadata:: creader:: { CStore , LoadedMacro } ;
15
15
use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
16
16
use rustc_middle:: ty:: { self , TyCtxt } ;
17
+ use rustc_span:: def_id:: LOCAL_CRATE ;
17
18
use rustc_span:: hygiene:: MacroKind ;
18
19
use rustc_span:: symbol:: { kw, sym, Symbol } ;
19
20
@@ -444,24 +445,32 @@ pub(crate) fn build_impl(
444
445
445
446
let associated_trait = tcx. impl_trait_ref ( did) . map ( ty:: EarlyBinder :: skip_binder) ;
446
447
448
+ // Do not inline compiler-internal items unless we're a compiler-internal crate.
449
+ let is_compiler_internal = |did| {
450
+ if let Some ( stab) = tcx. lookup_stability ( did) {
451
+ stab. is_unstable ( ) && stab. feature == sym:: rustc_private
452
+ } else {
453
+ false
454
+ }
455
+ } ;
456
+ let document_compiler_internal = is_compiler_internal ( LOCAL_CRATE . as_def_id ( ) ) ;
457
+ let is_directly_public = |cx : & mut DocContext < ' _ > , did| {
458
+ if !cx. cache . effective_visibilities . is_directly_public ( tcx, did) {
459
+ return false ;
460
+ }
461
+ if !document_compiler_internal && is_compiler_internal ( did) {
462
+ return false ;
463
+ }
464
+ true
465
+ } ;
466
+
447
467
// Only inline impl if the implemented trait is
448
468
// reachable in rustdoc generated documentation
449
469
if !did. is_local ( )
450
470
&& let Some ( traitref) = associated_trait
471
+ && !is_directly_public ( cx, traitref. def_id )
451
472
{
452
- let did = traitref. def_id ;
453
- if !cx. cache . effective_visibilities . is_directly_public ( tcx, did) {
454
- return ;
455
- }
456
-
457
- if !tcx. features ( ) . rustc_private && !cx. render_options . force_unstable_if_unmarked {
458
- if let Some ( stab) = tcx. lookup_stability ( did)
459
- && stab. is_unstable ( )
460
- && stab. feature == sym:: rustc_private
461
- {
462
- return ;
463
- }
464
- }
473
+ return ;
465
474
}
466
475
467
476
let impl_item = match did. as_local ( ) {
@@ -484,21 +493,11 @@ pub(crate) fn build_impl(
484
493
485
494
// Only inline impl if the implementing type is
486
495
// reachable in rustdoc generated documentation
487
- if !did. is_local ( ) {
488
- if let Some ( did) = for_. def_id ( & cx. cache ) {
489
- if !cx. cache . effective_visibilities . is_directly_public ( tcx, did) {
490
- return ;
491
- }
492
-
493
- if !tcx. features ( ) . rustc_private && !cx. render_options . force_unstable_if_unmarked {
494
- if let Some ( stab) = tcx. lookup_stability ( did)
495
- && stab. is_unstable ( )
496
- && stab. feature == sym:: rustc_private
497
- {
498
- return ;
499
- }
500
- }
501
- }
496
+ if !did. is_local ( )
497
+ && let Some ( did) = for_. def_id ( & cx. cache )
498
+ && !is_directly_public ( cx, did)
499
+ {
500
+ return ;
502
501
}
503
502
504
503
let document_hidden = cx. render_options . document_hidden ;
0 commit comments