@@ -7,22 +7,12 @@ use rustc_span::symbol::Symbol;
7
7
use serde:: ser:: { Serialize , SerializeStruct , Serializer } ;
8
8
9
9
use crate :: clean;
10
- use crate :: clean:: types:: { FnDecl , FnRetTy , GenericBound , Generics , Type , WherePredicate } ;
10
+ use crate :: clean:: types:: { FnRetTy , Function , GenericBound , Generics , Type , WherePredicate } ;
11
11
use crate :: formats:: cache:: Cache ;
12
12
use crate :: formats:: item_type:: ItemType ;
13
13
use crate :: html:: markdown:: short_markdown_summary;
14
14
use crate :: html:: render:: { IndexItem , IndexItemFunctionType , RenderType , TypeWithKind } ;
15
15
16
- /// Indicates where an external crate can be found.
17
- crate enum ExternalLocation {
18
- /// Remote URL root of the external crate
19
- Remote ( String ) ,
20
- /// This external crate can be found in the local doc/ folder
21
- Local ,
22
- /// The external crate could not be found.
23
- Unknown ,
24
- }
25
-
26
16
/// Builds the search index from the collected metadata
27
17
crate fn build_index < ' tcx > ( krate : & clean:: Crate , cache : & mut Cache , tcx : TyCtxt < ' tcx > ) -> String {
28
18
let mut defid_to_pathid = FxHashMap :: default ( ) ;
@@ -42,7 +32,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
42
32
desc,
43
33
parent : Some ( did) ,
44
34
parent_idx : None ,
45
- search_type : get_index_search_type ( item, tcx, cache ) ,
35
+ search_type : get_function_type_for_search ( item, tcx) ,
46
36
aliases : item. attrs . get_doc_aliases ( ) ,
47
37
} ) ;
48
38
}
@@ -191,15 +181,14 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
191
181
)
192
182
}
193
183
194
- crate fn get_index_search_type < ' tcx > (
184
+ crate fn get_function_type_for_search < ' tcx > (
195
185
item : & clean:: Item ,
196
186
tcx : TyCtxt < ' tcx > ,
197
- cache : & Cache ,
198
187
) -> Option < IndexItemFunctionType > {
199
188
let ( mut inputs, mut output) = match * item. kind {
200
- clean:: FunctionItem ( ref f) => get_all_types ( & f . generics , & f . decl , tcx, cache ) ,
201
- clean:: MethodItem ( ref m, _) => get_all_types ( & m . generics , & m . decl , tcx, cache ) ,
202
- clean:: TyMethodItem ( ref m) => get_all_types ( & m . generics , & m . decl , tcx, cache ) ,
189
+ clean:: FunctionItem ( ref f) => get_fn_inputs_and_outputs ( f , tcx) ,
190
+ clean:: MethodItem ( ref m, _) => get_fn_inputs_and_outputs ( m , tcx) ,
191
+ clean:: TyMethodItem ( ref m) => get_fn_inputs_and_outputs ( m , tcx) ,
203
192
_ => return None ,
204
193
} ;
205
194
@@ -211,12 +200,12 @@ crate fn get_index_search_type<'tcx>(
211
200
212
201
fn get_index_type ( clean_type : & clean:: Type , generics : Vec < TypeWithKind > ) -> RenderType {
213
202
RenderType {
214
- name : get_index_type_name ( clean_type, true ) . map ( |s| s. as_str ( ) . to_ascii_lowercase ( ) ) ,
203
+ name : get_index_type_name ( clean_type) . map ( |s| s. as_str ( ) . to_ascii_lowercase ( ) ) ,
215
204
generics : if generics. is_empty ( ) { None } else { Some ( generics) } ,
216
205
}
217
206
}
218
207
219
- fn get_index_type_name ( clean_type : & clean:: Type , accept_generic : bool ) -> Option < Symbol > {
208
+ fn get_index_type_name ( clean_type : & clean:: Type ) -> Option < Symbol > {
220
209
match * clean_type {
221
210
clean:: Type :: Path { ref path, .. } => {
222
211
let path_segment = path. segments . last ( ) . unwrap ( ) ;
@@ -226,11 +215,10 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
226
215
let path = & bounds[ 0 ] . trait_ ;
227
216
Some ( path. segments . last ( ) . unwrap ( ) . name )
228
217
}
229
- clean:: Generic ( s) if accept_generic => Some ( s) ,
218
+ clean:: Generic ( s) => Some ( s) ,
230
219
clean:: Primitive ( ref p) => Some ( p. as_sym ( ) ) ,
231
- clean:: BorrowedRef { ref type_, .. } => get_index_type_name ( type_, accept_generic) ,
232
- clean:: Generic ( _)
233
- | clean:: BareFunction ( _)
220
+ clean:: BorrowedRef { ref type_, .. } => get_index_type_name ( type_) ,
221
+ clean:: BareFunction ( _)
234
222
| clean:: Tuple ( _)
235
223
| clean:: Slice ( _)
236
224
| clean:: Array ( _, _)
@@ -248,20 +236,19 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
248
236
///
249
237
/// Important note: It goes through generics recursively. So if you have
250
238
/// `T: Option<Result<(), ()>>`, it'll go into `Option` and then into `Result`.
251
- crate fn get_real_types < ' tcx > (
239
+ #[ instrument( level = "trace" , skip( tcx, res) ) ]
240
+ fn add_generics_and_bounds_as_types < ' tcx > (
252
241
generics : & Generics ,
253
242
arg : & Type ,
254
243
tcx : TyCtxt < ' tcx > ,
255
244
recurse : usize ,
256
245
res : & mut Vec < TypeWithKind > ,
257
- cache : & Cache ,
258
246
) {
259
247
fn insert_ty (
260
248
res : & mut Vec < TypeWithKind > ,
261
249
tcx : TyCtxt < ' _ > ,
262
250
ty : Type ,
263
251
mut generics : Vec < TypeWithKind > ,
264
- _cache : & Cache ,
265
252
) {
266
253
let is_full_generic = ty. is_full_generic ( ) ;
267
254
@@ -330,6 +317,7 @@ crate fn get_real_types<'tcx>(
330
317
331
318
if recurse >= 10 {
332
319
// FIXME: remove this whole recurse thing when the recursion bug is fixed
320
+ // See #59502 for the original issue.
333
321
return ;
334
322
}
335
323
@@ -350,32 +338,37 @@ crate fn get_real_types<'tcx>(
350
338
for param_def in poly_trait. generic_params . iter ( ) {
351
339
match & param_def. kind {
352
340
clean:: GenericParamDefKind :: Type { default : Some ( ty) , .. } => {
353
- get_real_types (
341
+ add_generics_and_bounds_as_types (
354
342
generics,
355
343
ty,
356
344
tcx,
357
345
recurse + 1 ,
358
346
& mut ty_generics,
359
- cache,
360
347
)
361
348
}
362
349
_ => { }
363
350
}
364
351
}
365
352
}
366
353
}
367
- insert_ty ( res, tcx, arg. clone ( ) , ty_generics, cache ) ;
354
+ insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
368
355
}
369
356
// Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
370
357
if let Some ( bound) = generics. params . iter ( ) . find ( |g| g. is_type ( ) && g. name == arg_s) {
371
358
let mut ty_generics = Vec :: new ( ) ;
372
359
for bound in bound. get_bounds ( ) . unwrap_or ( & [ ] ) {
373
360
if let Some ( path) = bound. get_trait_path ( ) {
374
361
let ty = Type :: Path { path } ;
375
- get_real_types ( generics, & ty, tcx, recurse + 1 , & mut ty_generics, cache) ;
362
+ add_generics_and_bounds_as_types (
363
+ generics,
364
+ & ty,
365
+ tcx,
366
+ recurse + 1 ,
367
+ & mut ty_generics,
368
+ ) ;
376
369
}
377
370
}
378
- insert_ty ( res, tcx, arg. clone ( ) , ty_generics, cache ) ;
371
+ insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
379
372
}
380
373
} else {
381
374
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
@@ -386,30 +379,31 @@ crate fn get_real_types<'tcx>(
386
379
let mut ty_generics = Vec :: new ( ) ;
387
380
if let Some ( arg_generics) = arg. generics ( ) {
388
381
for gen in arg_generics. iter ( ) {
389
- get_real_types ( generics, gen, tcx, recurse + 1 , & mut ty_generics, cache ) ;
382
+ add_generics_and_bounds_as_types ( generics, gen, tcx, recurse + 1 , & mut ty_generics) ;
390
383
}
391
384
}
392
- insert_ty ( res, tcx, arg. clone ( ) , ty_generics, cache ) ;
385
+ insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
393
386
}
394
387
}
395
388
396
389
/// Return the full list of types when bounds have been resolved.
397
390
///
398
391
/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return
399
392
/// `[u32, Display, Option]`.
400
- crate fn get_all_types < ' tcx > (
401
- generics : & Generics ,
402
- decl : & FnDecl ,
393
+ fn get_fn_inputs_and_outputs < ' tcx > (
394
+ func : & Function ,
403
395
tcx : TyCtxt < ' tcx > ,
404
- cache : & Cache ,
405
396
) -> ( Vec < TypeWithKind > , Vec < TypeWithKind > ) {
397
+ let decl = & func. decl ;
398
+ let generics = & func. generics ;
399
+
406
400
let mut all_types = Vec :: new ( ) ;
407
401
for arg in decl. inputs . values . iter ( ) {
408
402
if arg. type_ . is_self_type ( ) {
409
403
continue ;
410
404
}
411
405
let mut args = Vec :: new ( ) ;
412
- get_real_types ( generics, & arg. type_ , tcx, 0 , & mut args, cache ) ;
406
+ add_generics_and_bounds_as_types ( generics, & arg. type_ , tcx, 0 , & mut args) ;
413
407
if !args. is_empty ( ) {
414
408
all_types. extend ( args) ;
415
409
} else {
@@ -423,7 +417,7 @@ crate fn get_all_types<'tcx>(
423
417
let mut ret_types = Vec :: new ( ) ;
424
418
match decl. output {
425
419
FnRetTy :: Return ( ref return_type) => {
426
- get_real_types ( generics, return_type, tcx, 0 , & mut ret_types, cache ) ;
420
+ add_generics_and_bounds_as_types ( generics, return_type, tcx, 0 , & mut ret_types) ;
427
421
if ret_types. is_empty ( ) {
428
422
if let Some ( kind) =
429
423
return_type. def_id_no_primitives ( ) . map ( |did| tcx. def_kind ( did) . into ( ) )
0 commit comments