@@ -241,8 +241,10 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
241
241
/// The point of this function is to replace bounds with types.
242
242
///
243
243
/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return
244
- /// `[Display, Option]` (we just returns the list of the types, we don't care about the
245
- /// wrapped types in here).
244
+ /// `[Display, Option]`. If a type parameter has no trait bound, it is discarded.
245
+ ///
246
+ /// Important note: It goes through generics recursively. So if you have
247
+ /// `T: Option<Result<(), ()>>`, it'll go into `Option` and then into `Result`.
246
248
crate fn get_real_types < ' tcx > (
247
249
generics : & Generics ,
248
250
arg : & Type ,
@@ -326,7 +328,10 @@ crate fn get_real_types<'tcx>(
326
328
return ;
327
329
}
328
330
331
+ // If this argument is a type parameter and not a trait bound or a type, we need to look
332
+ // for its bounds.
329
333
if let Type :: Generic ( arg_s) = * arg {
334
+ // First we check if the bounds are in a `where` predicate...
330
335
if let Some ( where_pred) = generics. where_predicates . iter ( ) . find ( |g| match g {
331
336
WherePredicate :: BoundPredicate { ty, .. } => {
332
337
ty. def_id_no_primitives ( ) == arg. def_id_no_primitives ( )
@@ -349,6 +354,7 @@ crate fn get_real_types<'tcx>(
349
354
}
350
355
insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
351
356
}
357
+ // Otherwise we check if the trait bounds are "inlined" like `T: Option<u32>`...
352
358
if let Some ( bound) = generics. params . iter ( ) . find ( |g| g. is_type ( ) && g. name == arg_s) {
353
359
let mut ty_generics = Vec :: new ( ) ;
354
360
for bound in bound. get_bounds ( ) . unwrap_or ( & [ ] ) {
@@ -360,6 +366,11 @@ crate fn get_real_types<'tcx>(
360
366
insert_ty ( res, tcx, arg. clone ( ) , ty_generics) ;
361
367
}
362
368
} else {
369
+ // This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
370
+ // looking at `Option`, we enter this "else" condition, otherwise if it's `T`, we don't.
371
+ //
372
+ // So in here, we can add it directly and look for its own type parameters (so for `Option`,
373
+ // we will look for them but not for `T`).
363
374
let mut ty_generics = Vec :: new ( ) ;
364
375
if let Some ( arg_generics) = arg. generics ( ) {
365
376
for gen in arg_generics. iter ( ) {
0 commit comments