@@ -258,45 +258,52 @@ crate fn get_real_types<'tcx>(
258
258
) {
259
259
let is_full_generic = ty. is_full_generic ( ) ;
260
260
261
- if is_full_generic && generics. len ( ) == 1 {
262
- // In this case, no need to go through an intermediate state if the generics
263
- // contains only one element.
264
- //
265
- // For example:
266
- //
267
- // fn foo<T: Display>(r: Option<T>) {}
268
- //
269
- // In this case, it would contain:
270
- //
271
- // ```
272
- // [{
273
- // name: "option",
274
- // generics: [{
275
- // name: "",
276
- // generics: [
277
- // name: "Display",
278
- // generics: []
279
- // }]
280
- // }]
281
- // }]
282
- // ```
283
- //
284
- // After removing the intermediate (unnecessary) full generic, it'll become:
285
- //
286
- // ```
287
- // [{
288
- // name: "option",
289
- // generics: [{
290
- // name: "Display",
291
- // generics: []
292
- // }]
293
- // }]
294
- // ```
295
- //
296
- // To be noted that it can work if there is ONLY ONE generic, otherwise we still
297
- // need to keep it as is!
298
- res. push ( generics. pop ( ) . unwrap ( ) ) ;
299
- return ;
261
+ if is_full_generic {
262
+ if generics. is_empty ( ) {
263
+ // This is a type parameter with no trait bounds (for example: `T` in
264
+ // `fn f<T>(p: T)`, so not useful for the rustdoc search because we would end up
265
+ // with an empty type with an empty name. Let's just discard it.
266
+ return ;
267
+ } else if generics. len ( ) == 1 {
268
+ // In this case, no need to go through an intermediate state if the type parameter
269
+ // contains only one trait bound.
270
+ //
271
+ // For example:
272
+ //
273
+ // `fn foo<T: Display>(r: Option<T>) {}`
274
+ //
275
+ // In this case, it would contain:
276
+ //
277
+ // ```
278
+ // [{
279
+ // name: "option",
280
+ // generics: [{
281
+ // name: "",
282
+ // generics: [
283
+ // name: "Display",
284
+ // generics: []
285
+ // }]
286
+ // }]
287
+ // }]
288
+ // ```
289
+ //
290
+ // After removing the intermediate (unnecessary) type parameter, it'll become:
291
+ //
292
+ // ```
293
+ // [{
294
+ // name: "option",
295
+ // generics: [{
296
+ // name: "Display",
297
+ // generics: []
298
+ // }]
299
+ // }]
300
+ // ```
301
+ //
302
+ // To be noted that it can work if there is ONLY ONE trait bound, otherwise we still
303
+ // need to keep it as is!
304
+ res. push ( generics. pop ( ) . unwrap ( ) ) ;
305
+ return ;
306
+ }
300
307
}
301
308
let mut index_ty = get_index_type ( & ty, generics) ;
302
309
if index_ty. name . as_ref ( ) . map ( |s| s. is_empty ( ) ) . unwrap_or ( true ) {
0 commit comments