@@ -6,7 +6,7 @@ use rustc_middle::middle::privacy::AccessLevels;
66use rustc_middle:: ty:: TyCtxt ;
77use rustc_span:: symbol:: sym;
88
9- use crate :: clean:: { self , ItemId , PrimitiveType } ;
9+ use crate :: clean:: { self , ExternalCrate , ItemId , PrimitiveType } ;
1010use crate :: config:: RenderOptions ;
1111use crate :: core:: DocContext ;
1212use crate :: fold:: DocFolder ;
@@ -15,6 +15,7 @@ use crate::formats::Impl;
1515use crate :: html:: markdown:: short_markdown_summary;
1616use crate :: html:: render:: cache:: { get_index_search_type, ExternalLocation } ;
1717use crate :: html:: render:: IndexItem ;
18+ use crate :: visit_lib:: LibEmbargoVisitor ;
1819
1920/// This cache is used to store information about the [`clean::Crate`] being
2021/// rendered in order to provide more useful documentation. This contains
@@ -139,19 +140,27 @@ impl Cache {
139140 /// in `krate` due to the data being moved into the `Cache`.
140141 crate fn populate ( cx : & mut DocContext < ' _ > , mut krate : clean:: Crate ) -> clean:: Crate {
141142 let tcx = cx. tcx ;
142- let render_options = & cx. render_options ;
143143
144144 // Crawl the crate to build various caches used for the output
145145 debug ! ( ?cx. cache. crate_version) ;
146146 cx. cache . traits = krate. external_traits . take ( ) ;
147- let RenderOptions { extern_html_root_takes_precedence, output : dst, .. } = render_options;
147+
148+ let mut externs = Vec :: new ( ) ;
149+ for & cnum in cx. tcx . crates ( ( ) ) {
150+ externs. push ( ExternalCrate { crate_num : cnum } ) ;
151+ // Analyze doc-reachability for extern items
152+ LibEmbargoVisitor :: new ( cx) . visit_lib ( cnum) ;
153+ }
154+
155+ let RenderOptions { extern_html_root_takes_precedence, output : dst, .. } =
156+ & cx. render_options ;
148157
149158 // Cache where all our extern crates are located
150159 // FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
151- for & e in & krate . externs {
160+ for e in externs {
152161 let name = e. name ( tcx) ;
153162 let extern_url =
154- render_options. extern_html_root_urls . get ( & * name. as_str ( ) ) . map ( |u| & * * u) ;
163+ cx . render_options . extern_html_root_urls . get ( & * name. as_str ( ) ) . map ( |u| & * * u) ;
155164 let location = e. location ( extern_url, * extern_html_root_takes_precedence, dst, tcx) ;
156165 cx. cache . extern_locations . insert ( e. crate_num , location) ;
157166 cx. cache . external_paths . insert ( e. def_id ( ) , ( vec ! [ name. to_string( ) ] , ItemType :: Module ) ) ;
0 commit comments