@@ -131,14 +131,7 @@ struct CacheBuilder<'a, 'tcx> {
131131}
132132
133133impl Cache {
134- crate fn from_krate < ' tcx > (
135- render_info : RenderInfo ,
136- document_private : bool ,
137- extern_html_root_urls : & BTreeMap < String , String > ,
138- dst : & Path ,
139- mut krate : clean:: Crate ,
140- tcx : TyCtxt < ' tcx > ,
141- ) -> ( clean:: Crate , Cache ) {
134+ crate fn new ( render_info : RenderInfo , document_private : bool ) -> Self {
142135 // Crawl the crate to build various caches used for the output
143136 let RenderInfo {
144137 inlined : _,
@@ -154,21 +147,31 @@ impl Cache {
154147 let external_paths =
155148 external_paths. into_iter ( ) . map ( |( k, ( v, t) ) | ( k, ( v, ItemType :: from ( t) ) ) ) . collect ( ) ;
156149
157- let mut cache = Cache {
150+ Cache {
158151 external_paths,
159152 exact_paths,
160- parent_is_trait_impl : false ,
161- stripped_mod : false ,
162153 access_levels,
163- crate_version : krate. version . take ( ) ,
164154 document_private,
165- traits : krate. external_traits . replace ( Default :: default ( ) ) ,
166155 deref_trait_did,
167156 deref_mut_trait_did,
168157 owned_box_did,
169- masked_crates : mem:: take ( & mut krate. masked_crates ) ,
170158 ..Cache :: default ( )
171- } ;
159+ }
160+ }
161+
162+ /// Populates the `Cache` with more data. The returned `Crate` will be missing some data that was
163+ /// in `krate` due to the data being moved into the `Cache`.
164+ crate fn populate (
165+ & mut self ,
166+ mut krate : clean:: Crate ,
167+ tcx : TyCtxt < ' _ > ,
168+ extern_html_root_urls : & BTreeMap < String , String > ,
169+ dst : & Path ,
170+ ) -> clean:: Crate {
171+ self . crate_version = krate. version . take ( ) ;
172+ debug ! ( ?self . crate_version) ;
173+ self . traits = krate. external_traits . take ( ) ;
174+ self . masked_crates = mem:: take ( & mut krate. masked_crates ) ;
172175
173176 // Cache where all our extern crates are located
174177 // FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
@@ -181,12 +184,11 @@ impl Cache {
181184 _ => PathBuf :: new ( ) ,
182185 } ;
183186 let extern_url = extern_html_root_urls. get ( & * e. name . as_str ( ) ) . map ( |u| & * * u) ;
184- cache
185- . extern_locations
187+ self . extern_locations
186188 . insert ( n, ( e. name , src_root, extern_location ( e, extern_url, & dst) ) ) ;
187189
188190 let did = DefId { krate : n, index : CRATE_DEF_INDEX } ;
189- cache . external_paths . insert ( did, ( vec ! [ e. name. to_string( ) ] , ItemType :: Module ) ) ;
191+ self . external_paths . insert ( did, ( vec ! [ e. name. to_string( ) ] , ItemType :: Module ) ) ;
190192 }
191193
192194 // Cache where all known primitives have their documentation located.
@@ -195,27 +197,26 @@ impl Cache {
195197 // reverse topological order.
196198 for & ( _, ref e) in krate. externs . iter ( ) . rev ( ) {
197199 for & ( def_id, prim) in & e. primitives {
198- cache . primitive_locations . insert ( prim, def_id) ;
200+ self . primitive_locations . insert ( prim, def_id) ;
199201 }
200202 }
201203 for & ( def_id, prim) in & krate. primitives {
202- cache . primitive_locations . insert ( prim, def_id) ;
204+ self . primitive_locations . insert ( prim, def_id) ;
203205 }
204206
205- cache . stack . push ( krate. name . to_string ( ) ) ;
207+ self . stack . push ( krate. name . to_string ( ) ) ;
206208
207- krate = CacheBuilder { tcx, cache : & mut cache, empty_cache : Cache :: default ( ) }
208- . fold_crate ( krate) ;
209+ krate = CacheBuilder { tcx, cache : self , empty_cache : Cache :: default ( ) } . fold_crate ( krate) ;
209210
210- for ( trait_did, dids, impl_) in cache . orphan_trait_impls . drain ( ..) {
211- if cache . traits . contains_key ( & trait_did) {
211+ for ( trait_did, dids, impl_) in self . orphan_trait_impls . drain ( ..) {
212+ if self . traits . contains_key ( & trait_did) {
212213 for did in dids {
213- cache . impls . entry ( did) . or_default ( ) . push ( impl_. clone ( ) ) ;
214+ self . impls . entry ( did) . or_default ( ) . push ( impl_. clone ( ) ) ;
214215 }
215216 }
216217 }
217218
218- ( krate, cache )
219+ krate
219220 }
220221}
221222
0 commit comments