@@ -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,32 @@ 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+         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+ 
447467    // Only inline impl if the implemented trait is 
448468    // reachable in rustdoc generated documentation 
449469    if  !did. is_local ( ) 
450470        && let  Some ( traitref)  = associated_trait
471+         && !is_directly_public ( cx,  traitref. def_id ) 
451472    { 
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 ; 
465474    } 
466475
467476    let  impl_item = match  did. as_local ( )  { 
@@ -484,21 +493,11 @@ pub(crate) fn build_impl(
484493
485494    // Only inline impl if the implementing type is 
486495    // 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 ; 
502501    } 
503502
504503    let  document_hidden = cx. render_options . document_hidden ; 
0 commit comments