@@ -131,14 +131,7 @@ struct CacheBuilder<'a, 'tcx> {
131
131
}
132
132
133
133
impl 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 {
142
135
// Crawl the crate to build various caches used for the output
143
136
let RenderInfo {
144
137
inlined : _,
@@ -154,21 +147,31 @@ impl Cache {
154
147
let external_paths =
155
148
external_paths. into_iter ( ) . map ( |( k, ( v, t) ) | ( k, ( v, ItemType :: from ( t) ) ) ) . collect ( ) ;
156
149
157
- let mut cache = Cache {
150
+ Cache {
158
151
external_paths,
159
152
exact_paths,
160
- parent_is_trait_impl : false ,
161
- stripped_mod : false ,
162
153
access_levels,
163
- crate_version : krate. version . take ( ) ,
164
154
document_private,
165
- traits : krate. external_traits . replace ( Default :: default ( ) ) ,
166
155
deref_trait_did,
167
156
deref_mut_trait_did,
168
157
owned_box_did,
169
- masked_crates : mem:: take ( & mut krate. masked_crates ) ,
170
158
..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 ) ;
172
175
173
176
// Cache where all our extern crates are located
174
177
// 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 {
181
184
_ => PathBuf :: new ( ) ,
182
185
} ;
183
186
let extern_url = extern_html_root_urls. get ( & * e. name . as_str ( ) ) . map ( |u| & * * u) ;
184
- cache
185
- . extern_locations
187
+ self . extern_locations
186
188
. insert ( n, ( e. name , src_root, extern_location ( e, extern_url, & dst) ) ) ;
187
189
188
190
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 ) ) ;
190
192
}
191
193
192
194
// Cache where all known primitives have their documentation located.
@@ -195,27 +197,26 @@ impl Cache {
195
197
// reverse topological order.
196
198
for & ( _, ref e) in krate. externs . iter ( ) . rev ( ) {
197
199
for & ( def_id, prim) in & e. primitives {
198
- cache . primitive_locations . insert ( prim, def_id) ;
200
+ self . primitive_locations . insert ( prim, def_id) ;
199
201
}
200
202
}
201
203
for & ( def_id, prim) in & krate. primitives {
202
- cache . primitive_locations . insert ( prim, def_id) ;
204
+ self . primitive_locations . insert ( prim, def_id) ;
203
205
}
204
206
205
- cache . stack . push ( krate. name . to_string ( ) ) ;
207
+ self . stack . push ( krate. name . to_string ( ) ) ;
206
208
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) ;
209
210
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) {
212
213
for did in dids {
213
- cache . impls . entry ( did) . or_default ( ) . push ( impl_. clone ( ) ) ;
214
+ self . impls . entry ( did) . or_default ( ) . push ( impl_. clone ( ) ) ;
214
215
}
215
216
}
216
217
}
217
218
218
- ( krate, cache )
219
+ krate
219
220
}
220
221
}
221
222
0 commit comments