@@ -259,66 +259,68 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Life
259
259
}
260
260
}
261
261
262
- impl < ' tcx > Clean < ' tcx , Option < WherePredicate > > for hir:: WherePredicate < ' tcx > {
263
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < WherePredicate > {
264
- if !self . in_where_clause ( ) {
265
- return None ;
266
- }
267
- Some ( match * self {
268
- hir:: WherePredicate :: BoundPredicate ( ref wbp) => {
269
- let bound_params = wbp
270
- . bound_generic_params
271
- . iter ( )
272
- . map ( |param| {
273
- // Higher-ranked params must be lifetimes.
274
- // Higher-ranked lifetimes can't have bounds.
275
- assert_matches ! (
276
- param,
277
- hir:: GenericParam { kind: hir:: GenericParamKind :: Lifetime { .. } , .. }
278
- ) ;
279
- Lifetime ( param. name . ident ( ) . name )
280
- } )
281
- . collect ( ) ;
282
- WherePredicate :: BoundPredicate {
283
- ty : clean_ty ( wbp. bounded_ty , cx) ,
284
- bounds : wbp. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
285
- bound_params,
286
- }
262
+ fn clean_where_predicate < ' tcx > (
263
+ predicate : & hir:: WherePredicate < ' tcx > ,
264
+ cx : & mut DocContext < ' tcx > ,
265
+ ) -> Option < WherePredicate > {
266
+ if !predicate. in_where_clause ( ) {
267
+ return None ;
268
+ }
269
+ Some ( match * predicate {
270
+ hir:: WherePredicate :: BoundPredicate ( ref wbp) => {
271
+ let bound_params = wbp
272
+ . bound_generic_params
273
+ . iter ( )
274
+ . map ( |param| {
275
+ // Higher-ranked params must be lifetimes.
276
+ // Higher-ranked lifetimes can't have bounds.
277
+ assert_matches ! (
278
+ param,
279
+ hir:: GenericParam { kind: hir:: GenericParamKind :: Lifetime { .. } , .. }
280
+ ) ;
281
+ Lifetime ( param. name . ident ( ) . name )
282
+ } )
283
+ . collect ( ) ;
284
+ WherePredicate :: BoundPredicate {
285
+ ty : clean_ty ( wbp. bounded_ty , cx) ,
286
+ bounds : wbp. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
287
+ bound_params,
287
288
}
289
+ }
288
290
289
- hir:: WherePredicate :: RegionPredicate ( ref wrp) => WherePredicate :: RegionPredicate {
290
- lifetime : clean_lifetime ( wrp. lifetime , cx) ,
291
- bounds : wrp. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
292
- } ,
291
+ hir:: WherePredicate :: RegionPredicate ( ref wrp) => WherePredicate :: RegionPredicate {
292
+ lifetime : clean_lifetime ( wrp. lifetime , cx) ,
293
+ bounds : wrp. bounds . iter ( ) . filter_map ( |x| clean_generic_bound ( x, cx) ) . collect ( ) ,
294
+ } ,
293
295
294
- hir:: WherePredicate :: EqPredicate ( ref wrp) => WherePredicate :: EqPredicate {
295
- lhs : clean_ty ( wrp. lhs_ty , cx) ,
296
- rhs : clean_ty ( wrp. rhs_ty , cx) . into ( ) ,
297
- } ,
298
- } )
299
- }
296
+ hir:: WherePredicate :: EqPredicate ( ref wrp) => WherePredicate :: EqPredicate {
297
+ lhs : clean_ty ( wrp. lhs_ty , cx) ,
298
+ rhs : clean_ty ( wrp. rhs_ty , cx) . into ( ) ,
299
+ } ,
300
+ } )
300
301
}
301
302
302
- impl < ' tcx > Clean < ' tcx , Option < WherePredicate > > for ty:: Predicate < ' tcx > {
303
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < WherePredicate > {
304
- let bound_predicate = self . kind ( ) ;
305
- match bound_predicate. skip_binder ( ) {
306
- ty:: PredicateKind :: Trait ( pred) => {
307
- clean_poly_trait_predicate ( bound_predicate. rebind ( pred) , cx)
308
- }
309
- ty:: PredicateKind :: RegionOutlives ( pred) => clean_region_outlives_predicate ( pred) ,
310
- ty:: PredicateKind :: TypeOutlives ( pred) => clean_type_outlives_predicate ( pred, cx) ,
311
- ty:: PredicateKind :: Projection ( pred) => Some ( clean_projection_predicate ( pred, cx) ) ,
312
- ty:: PredicateKind :: ConstEvaluatable ( ..) => None ,
313
- ty:: PredicateKind :: WellFormed ( ..) => None ,
314
-
315
- ty:: PredicateKind :: Subtype ( ..)
316
- | ty:: PredicateKind :: Coerce ( ..)
317
- | ty:: PredicateKind :: ObjectSafe ( ..)
318
- | ty:: PredicateKind :: ClosureKind ( ..)
319
- | ty:: PredicateKind :: ConstEquate ( ..)
320
- | ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => panic ! ( "not user writable" ) ,
303
+ pub ( crate ) fn clean_predicate < ' tcx > (
304
+ predicate : ty:: Predicate < ' tcx > ,
305
+ cx : & mut DocContext < ' tcx > ,
306
+ ) -> Option < WherePredicate > {
307
+ let bound_predicate = predicate. kind ( ) ;
308
+ match bound_predicate. skip_binder ( ) {
309
+ ty:: PredicateKind :: Trait ( pred) => {
310
+ clean_poly_trait_predicate ( bound_predicate. rebind ( pred) , cx)
321
311
}
312
+ ty:: PredicateKind :: RegionOutlives ( pred) => clean_region_outlives_predicate ( pred) ,
313
+ ty:: PredicateKind :: TypeOutlives ( pred) => clean_type_outlives_predicate ( pred, cx) ,
314
+ ty:: PredicateKind :: Projection ( pred) => Some ( clean_projection_predicate ( pred, cx) ) ,
315
+ ty:: PredicateKind :: ConstEvaluatable ( ..) => None ,
316
+ ty:: PredicateKind :: WellFormed ( ..) => None ,
317
+
318
+ ty:: PredicateKind :: Subtype ( ..)
319
+ | ty:: PredicateKind :: Coerce ( ..)
320
+ | ty:: PredicateKind :: ObjectSafe ( ..)
321
+ | ty:: PredicateKind :: ClosureKind ( ..)
322
+ | ty:: PredicateKind :: ConstEquate ( ..)
323
+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => panic ! ( "not user writable" ) ,
322
324
}
323
325
}
324
326
@@ -594,7 +596,11 @@ impl<'tcx> Clean<'tcx, Generics> for hir::Generics<'tcx> {
594
596
595
597
let mut generics = Generics {
596
598
params,
597
- where_predicates : self . predicates . iter ( ) . filter_map ( |x| x. clean ( cx) ) . collect ( ) ,
599
+ where_predicates : self
600
+ . predicates
601
+ . iter ( )
602
+ . filter_map ( |x| clean_where_predicate ( x, cx) )
603
+ . collect ( ) ,
598
604
} ;
599
605
600
606
// Some duplicates are generated for ?Sized bounds between type params and where
@@ -695,7 +701,7 @@ fn clean_ty_generics<'tcx>(
695
701
696
702
if let Some ( param_idx) = param_idx {
697
703
if let Some ( b) = impl_trait. get_mut ( & param_idx. into ( ) ) {
698
- let p: WherePredicate = p . clean ( cx) ?;
704
+ let p: WherePredicate = clean_predicate ( * p , cx) ?;
699
705
700
706
b. extend (
701
707
p. get_bounds ( )
@@ -752,7 +758,7 @@ fn clean_ty_generics<'tcx>(
752
758
// Now that `cx.impl_trait_bounds` is populated, we can process
753
759
// remaining predicates which could contain `impl Trait`.
754
760
let mut where_predicates =
755
- where_predicates. into_iter ( ) . flat_map ( |p| p . clean ( cx) ) . collect :: < Vec < _ > > ( ) ;
761
+ where_predicates. into_iter ( ) . flat_map ( |p| clean_predicate ( * p , cx) ) . collect :: < Vec < _ > > ( ) ;
756
762
757
763
// Type parameters have a Sized bound by default unless removed with
758
764
// ?Sized. Scan through the predicates and mark any type parameter with
0 commit comments