@@ -264,25 +264,21 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
264
264
. map ( |item| clean_middle_assoc_item ( item, cx) )
265
265
. collect ( ) ;
266
266
267
- let predicates = cx. tcx . predicates_of ( did) ;
268
- let generics = clean_ty_generics ( cx, cx. tcx . generics_of ( did) , predicates) ;
269
- let generics = filter_non_trait_generics ( did, generics) ;
267
+ let generics = clean_ty_generics ( cx, did) ;
270
268
let ( generics, supertrait_bounds) = separate_self_bounds ( generics) ;
271
269
clean:: Trait { def_id : did, generics, items : trait_items, bounds : supertrait_bounds }
272
270
}
273
271
274
272
fn build_trait_alias ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: TraitAlias {
275
- let predicates = cx. tcx . predicates_of ( did) ;
276
- let generics = clean_ty_generics ( cx, cx. tcx . generics_of ( did) , predicates) ;
273
+ let generics = clean_ty_generics ( cx, did) ;
277
274
let ( generics, bounds) = separate_self_bounds ( generics) ;
278
275
clean:: TraitAlias { generics, bounds }
279
276
}
280
277
281
278
pub ( super ) fn build_function ( cx : & mut DocContext < ' _ > , def_id : DefId ) -> Box < clean:: Function > {
282
279
let sig = cx. tcx . fn_sig ( def_id) . instantiate_identity ( ) ;
283
280
// The generics need to be cleaned before the signature.
284
- let mut generics =
285
- clean_ty_generics ( cx, cx. tcx . generics_of ( def_id) , cx. tcx . explicit_predicates_of ( def_id) ) ;
281
+ let mut generics = clean_ty_generics ( cx, def_id) ;
286
282
let bound_vars = clean_bound_vars ( sig. bound_vars ( ) ) ;
287
283
288
284
// At the time of writing early & late-bound params are stored separately in rustc,
@@ -311,30 +307,26 @@ pub(super) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clea
311
307
}
312
308
313
309
fn build_enum ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Enum {
314
- let predicates = cx. tcx . explicit_predicates_of ( did) ;
315
-
316
310
clean:: Enum {
317
- generics : clean_ty_generics ( cx, cx . tcx . generics_of ( did) , predicates ) ,
311
+ generics : clean_ty_generics ( cx, did) ,
318
312
variants : cx. tcx . adt_def ( did) . variants ( ) . iter ( ) . map ( |v| clean_variant_def ( v, cx) ) . collect ( ) ,
319
313
}
320
314
}
321
315
322
316
fn build_struct ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Struct {
323
- let predicates = cx. tcx . explicit_predicates_of ( did) ;
324
317
let variant = cx. tcx . adt_def ( did) . non_enum_variant ( ) ;
325
318
326
319
clean:: Struct {
327
320
ctor_kind : variant. ctor_kind ( ) ,
328
- generics : clean_ty_generics ( cx, cx . tcx . generics_of ( did) , predicates ) ,
321
+ generics : clean_ty_generics ( cx, did) ,
329
322
fields : variant. fields . iter ( ) . map ( |x| clean_middle_field ( x, cx) ) . collect ( ) ,
330
323
}
331
324
}
332
325
333
326
fn build_union ( cx : & mut DocContext < ' _ > , did : DefId ) -> clean:: Union {
334
- let predicates = cx. tcx . explicit_predicates_of ( did) ;
335
327
let variant = cx. tcx . adt_def ( did) . non_enum_variant ( ) ;
336
328
337
- let generics = clean_ty_generics ( cx, cx . tcx . generics_of ( did) , predicates ) ;
329
+ let generics = clean_ty_generics ( cx, did) ;
338
330
let fields = variant. fields . iter ( ) . map ( |x| clean_middle_field ( x, cx) ) . collect ( ) ;
339
331
clean:: Union { generics, fields }
340
332
}
@@ -344,14 +336,13 @@ fn build_type_alias(
344
336
did : DefId ,
345
337
ret : & mut Vec < Item > ,
346
338
) -> Box < clean:: TypeAlias > {
347
- let predicates = cx. tcx . explicit_predicates_of ( did) ;
348
339
let ty = cx. tcx . type_of ( did) . instantiate_identity ( ) ;
349
340
let type_ = clean_middle_ty ( ty:: Binder :: dummy ( ty) , cx, Some ( did) , None ) ;
350
341
let inner_type = clean_ty_alias_inner_type ( ty, cx, ret) ;
351
342
352
343
Box :: new ( clean:: TypeAlias {
353
344
type_,
354
- generics : clean_ty_generics ( cx, cx . tcx . generics_of ( did) , predicates ) ,
345
+ generics : clean_ty_generics ( cx, did) ,
355
346
inner_type,
356
347
item_type : None ,
357
348
} )
@@ -483,7 +474,6 @@ pub(crate) fn build_impl(
483
474
}
484
475
485
476
let document_hidden = cx. render_options . document_hidden ;
486
- let predicates = tcx. explicit_predicates_of ( did) ;
487
477
let ( trait_items, generics) = match impl_item {
488
478
Some ( impl_) => (
489
479
impl_
@@ -549,9 +539,7 @@ pub(crate) fn build_impl(
549
539
} )
550
540
. map ( |item| clean_middle_assoc_item ( item, cx) )
551
541
. collect :: < Vec < _ > > ( ) ,
552
- clean:: enter_impl_trait ( cx, |cx| {
553
- clean_ty_generics ( cx, tcx. generics_of ( did) , predicates)
554
- } ) ,
542
+ clean:: enter_impl_trait ( cx, |cx| clean_ty_generics ( cx, did) ) ,
555
543
) ,
556
544
} ;
557
545
let polarity = tcx. impl_polarity ( did) ;
@@ -713,8 +701,7 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
713
701
}
714
702
715
703
fn build_const_item ( cx : & mut DocContext < ' _ > , def_id : DefId ) -> clean:: Constant {
716
- let mut generics =
717
- clean_ty_generics ( cx, cx. tcx . generics_of ( def_id) , cx. tcx . explicit_predicates_of ( def_id) ) ;
704
+ let mut generics = clean_ty_generics ( cx, def_id) ;
718
705
clean:: simplify:: move_bounds_to_generic_parameters ( & mut generics) ;
719
706
let ty = clean_middle_ty (
720
707
ty:: Binder :: dummy ( cx. tcx . type_of ( def_id) . instantiate_identity ( ) ) ,
@@ -761,44 +748,6 @@ fn build_macro(
761
748
}
762
749
}
763
750
764
- /// A trait's generics clause actually contains all of the predicates for all of
765
- /// its associated types as well. We specifically move these clauses to the
766
- /// associated types instead when displaying, so when we're generating the
767
- /// generics for the trait itself we need to be sure to remove them.
768
- /// We also need to remove the implied "recursive" Self: Trait bound.
769
- ///
770
- /// The inverse of this filtering logic can be found in the `Clean`
771
- /// implementation for `AssociatedType`
772
- fn filter_non_trait_generics ( trait_did : DefId , mut g : clean:: Generics ) -> clean:: Generics {
773
- for pred in & mut g. where_predicates {
774
- if let clean:: WherePredicate :: BoundPredicate { ty : clean:: SelfTy , ref mut bounds, .. } =
775
- * pred
776
- {
777
- bounds. retain ( |bound| match bound {
778
- clean:: GenericBound :: TraitBound ( clean:: PolyTrait { trait_, .. } , _) => {
779
- trait_. def_id ( ) != trait_did
780
- }
781
- _ => true ,
782
- } ) ;
783
- }
784
- }
785
-
786
- g. where_predicates . retain ( |pred| match pred {
787
- clean:: WherePredicate :: BoundPredicate {
788
- ty :
789
- clean:: QPath ( box clean:: QPathData {
790
- self_type : clean:: Generic ( _) ,
791
- trait_ : Some ( trait_) ,
792
- ..
793
- } ) ,
794
- bounds,
795
- ..
796
- } => !bounds. is_empty ( ) && trait_. def_id ( ) != trait_did,
797
- _ => true ,
798
- } ) ;
799
- g
800
- }
801
-
802
751
fn separate_self_bounds ( mut g : clean:: Generics ) -> ( clean:: Generics , Vec < clean:: GenericBound > ) {
803
752
let mut ty_bounds = Vec :: new ( ) ;
804
753
g. where_predicates . retain ( |pred| match * pred {
0 commit comments