@@ -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,24 @@ 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
+ tcx. lookup_stability ( did)
451
+ . is_some_and ( |stab| stab. is_unstable ( ) && stab. feature == sym:: rustc_private)
452
+ } ;
453
+ let document_compiler_internal = is_compiler_internal ( LOCAL_CRATE . as_def_id ( ) ) ;
454
+ let is_directly_public = |cx : & mut DocContext < ' _ > , did| {
455
+ cx. cache . effective_visibilities . is_directly_public ( tcx, did)
456
+ && ( document_compiler_internal || !is_compiler_internal ( did) )
457
+ } ;
458
+
447
459
// Only inline impl if the implemented trait is
448
460
// reachable in rustdoc generated documentation
449
461
if !did. is_local ( )
450
462
&& let Some ( traitref) = associated_trait
463
+ && !is_directly_public ( cx, traitref. def_id )
451
464
{
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
- }
465
+ return ;
465
466
}
466
467
467
468
let impl_item = match did. as_local ( ) {
@@ -484,21 +485,11 @@ pub(crate) fn build_impl(
484
485
485
486
// Only inline impl if the implementing type is
486
487
// 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
- }
488
+ if !did. is_local ( )
489
+ && let Some ( did) = for_. def_id ( & cx. cache )
490
+ && !is_directly_public ( cx, did)
491
+ {
492
+ return ;
502
493
}
503
494
504
495
let document_hidden = cx. render_options . document_hidden ;
0 commit comments