@@ -14,6 +14,7 @@ use rustc_hir::Mutability;
1414use rustc_metadata:: creader:: { CStore , LoadedMacro } ;
1515use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
1616use rustc_middle:: ty:: { self , TyCtxt } ;
17+ use rustc_span:: def_id:: LOCAL_CRATE ;
1718use rustc_span:: hygiene:: MacroKind ;
1819use rustc_span:: symbol:: { kw, sym, Symbol } ;
1920
@@ -444,24 +445,24 @@ pub(crate) fn build_impl(
444445
445446 let associated_trait = tcx. impl_trait_ref ( did) . map ( ty:: EarlyBinder :: skip_binder) ;
446447
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+
447459 // Only inline impl if the implemented trait is
448460 // reachable in rustdoc generated documentation
449461 if !did. is_local ( )
450462 && let Some ( traitref) = associated_trait
463+ && !is_directly_public ( cx, traitref. def_id )
451464 {
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 ;
465466 }
466467
467468 let impl_item = match did. as_local ( ) {
@@ -484,21 +485,11 @@ pub(crate) fn build_impl(
484485
485486 // Only inline impl if the implementing type is
486487 // 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 ;
502493 }
503494
504495 let document_hidden = cx. render_options . document_hidden ;
0 commit comments