@@ -7,22 +7,12 @@ use rustc_span::symbol::Symbol;
77use serde:: ser:: { Serialize , SerializeStruct , Serializer } ;
88
99use crate :: clean;
10- use crate :: clean:: types:: { FnDecl , FnRetTy , GenericBound , Generics , Type , WherePredicate } ;
10+ use crate :: clean:: types:: { FnRetTy , Function , GenericBound , Generics , Type , WherePredicate } ;
1111use crate :: formats:: cache:: Cache ;
1212use crate :: formats:: item_type:: ItemType ;
1313use crate :: html:: markdown:: short_markdown_summary;
1414use crate :: html:: render:: { IndexItem , IndexItemFunctionType , RenderType , TypeWithKind } ;
1515
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-
2616/// Builds the search index from the collected metadata
2717crate fn build_index < ' tcx > ( krate : & clean:: Crate , cache : & mut Cache , tcx : TyCtxt < ' tcx > ) -> String {
2818 let mut defid_to_pathid = FxHashMap :: default ( ) ;
@@ -42,7 +32,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
4232 desc,
4333 parent : Some ( did) ,
4434 parent_idx : None ,
45- search_type : get_index_search_type ( item, tcx, cache ) ,
35+ search_type : get_function_type_for_search ( item, tcx) ,
4636 aliases : item. attrs . get_doc_aliases ( ) ,
4737 } ) ;
4838 }
@@ -191,15 +181,14 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
191181 )
192182}
193183
194- crate fn get_index_search_type < ' tcx > (
184+ crate fn get_function_type_for_search < ' tcx > (
195185 item : & clean:: Item ,
196186 tcx : TyCtxt < ' tcx > ,
197- cache : & Cache ,
198187) -> Option < IndexItemFunctionType > {
199188 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) ,
203192 _ => return None ,
204193 } ;
205194
@@ -211,12 +200,12 @@ crate fn get_index_search_type<'tcx>(
211200
212201fn get_index_type ( clean_type : & clean:: Type , generics : Vec < TypeWithKind > ) -> RenderType {
213202 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 ( ) ) ,
215204 generics : if generics. is_empty ( ) { None } else { Some ( generics) } ,
216205 }
217206}
218207
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 > {
220209 match * clean_type {
221210 clean:: Type :: Path { ref path, .. } => {
222211 let path_segment = path. segments . last ( ) . unwrap ( ) ;
@@ -226,11 +215,10 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
226215 let path = & bounds[ 0 ] . trait_ ;
227216 Some ( path. segments . last ( ) . unwrap ( ) . name )
228217 }
229- clean:: Generic ( s) if accept_generic => Some ( s) ,
218+ clean:: Generic ( s) => Some ( s) ,
230219 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 ( _)
234222 | clean:: Tuple ( _)
235223 | clean:: Slice ( _)
236224 | clean:: Array ( _, _)
@@ -248,20 +236,19 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
248236///
249237/// Important note: It goes through generics recursively. So if you have
250238/// `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 > (
252241 generics : & Generics ,
253242 arg : & Type ,
254243 tcx : TyCtxt < ' tcx > ,
255244 recurse : usize ,
256245 res : & mut Vec < TypeWithKind > ,
257- cache : & Cache ,
258246) {
259247 fn insert_ty (
260248 res : & mut Vec < TypeWithKind > ,
261249 tcx : TyCtxt < ' _ > ,
262250 ty : Type ,
263251 mut generics : Vec < TypeWithKind > ,
264- _cache : & Cache ,
265252 ) {
266253 let is_full_generic = ty. is_full_generic ( ) ;
267254
@@ -330,6 +317,7 @@ crate fn get_real_types<'tcx>(
330317
331318 if recurse >= 10 {
332319 // FIXME: remove this whole recurse thing when the recursion bug is fixed
320+ // See #59502 for the original issue.
333321 return ;
334322 }
335323
@@ -350,32 +338,37 @@ crate fn get_real_types<'tcx>(
350338 for param_def in poly_trait. generic_params . iter ( ) {
351339 match & param_def. kind {
352340 clean:: GenericParamDefKind :: Type { default : Some ( ty) , .. } => {
353- get_real_types (
341+ add_generics_and_bounds_as_types (
354342 generics,
355343 ty,
356344 tcx,
357345 recurse + 1 ,
358346 & mut ty_generics,
359- cache,
360347 )
361348 }
362349 _ => { }
363350 }
364351 }
365352 }
366353 }
367- insert_ty ( res, tcx, arg. clone ( ) , ty_generics, cache ) ;
354+ insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
368355 }
369356 // Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
370357 if let Some ( bound) = generics. params . iter ( ) . find ( |g| g. is_type ( ) && g. name == arg_s) {
371358 let mut ty_generics = Vec :: new ( ) ;
372359 for bound in bound. get_bounds ( ) . unwrap_or ( & [ ] ) {
373360 if let Some ( path) = bound. get_trait_path ( ) {
374361 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+ ) ;
376369 }
377370 }
378- insert_ty ( res, tcx, arg. clone ( ) , ty_generics, cache ) ;
371+ insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
379372 }
380373 } else {
381374 // 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>(
386379 let mut ty_generics = Vec :: new ( ) ;
387380 if let Some ( arg_generics) = arg. generics ( ) {
388381 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) ;
390383 }
391384 }
392- insert_ty ( res, tcx, arg. clone ( ) , ty_generics, cache ) ;
385+ insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
393386 }
394387}
395388
396389/// Return the full list of types when bounds have been resolved.
397390///
398391/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return
399392/// `[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 ,
403395 tcx : TyCtxt < ' tcx > ,
404- cache : & Cache ,
405396) -> ( Vec < TypeWithKind > , Vec < TypeWithKind > ) {
397+ let decl = & func. decl ;
398+ let generics = & func. generics ;
399+
406400 let mut all_types = Vec :: new ( ) ;
407401 for arg in decl. inputs . values . iter ( ) {
408402 if arg. type_ . is_self_type ( ) {
409403 continue ;
410404 }
411405 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) ;
413407 if !args. is_empty ( ) {
414408 all_types. extend ( args) ;
415409 } else {
@@ -423,7 +417,7 @@ crate fn get_all_types<'tcx>(
423417 let mut ret_types = Vec :: new ( ) ;
424418 match decl. output {
425419 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) ;
427421 if ret_types. is_empty ( ) {
428422 if let Some ( kind) =
429423 return_type. def_id_no_primitives ( ) . map ( |did| tcx. def_kind ( did) . into ( ) )
0 commit comments