@@ -327,10 +327,12 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::Predicate<'tcx> {
327327 fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < WherePredicate > {
328328 let bound_predicate = self . kind ( ) ;
329329 match bound_predicate. skip_binder ( ) {
330- ty:: PredicateKind :: Trait ( pred) => bound_predicate. rebind ( pred) . clean ( cx) ,
331- ty:: PredicateKind :: RegionOutlives ( pred) => pred. clean ( cx) ,
332- ty:: PredicateKind :: TypeOutlives ( pred) => pred. clean ( cx) ,
333- ty:: PredicateKind :: Projection ( pred) => Some ( pred. clean ( cx) ) ,
330+ ty:: PredicateKind :: Trait ( pred) => {
331+ clean_poly_trait_predicate ( bound_predicate. rebind ( pred) , cx)
332+ }
333+ ty:: PredicateKind :: RegionOutlives ( pred) => clean_region_outlives_predicate ( pred, cx) ,
334+ ty:: PredicateKind :: TypeOutlives ( pred) => clean_type_outlives_predicate ( pred, cx) ,
335+ ty:: PredicateKind :: Projection ( pred) => Some ( clean_projection_predicate ( pred, cx) ) ,
334336 ty:: PredicateKind :: ConstEvaluatable ( ..) => None ,
335337 ty:: PredicateKind :: WellFormed ( ..) => None ,
336338
@@ -344,57 +346,56 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for ty::Predicate<'tcx> {
344346 }
345347}
346348
347- impl < ' tcx > Clean < ' tcx , Option < WherePredicate > > for ty:: PolyTraitPredicate < ' tcx > {
348- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < WherePredicate > {
349- // `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
350- if self . skip_binder ( ) . constness == ty:: BoundConstness :: ConstIfConst
351- && Some ( self . skip_binder ( ) . def_id ( ) ) == cx. tcx . lang_items ( ) . destruct_trait ( )
352- {
353- return None ;
354- }
355-
356- let poly_trait_ref = self . map_bound ( |pred| pred. trait_ref ) ;
357- Some ( WherePredicate :: BoundPredicate {
358- ty : clean_middle_ty ( poly_trait_ref. skip_binder ( ) . self_ty ( ) , cx, None ) ,
359- bounds : vec ! [ poly_trait_ref. clean( cx) ] ,
360- bound_params : Vec :: new ( ) ,
361- } )
349+ fn clean_poly_trait_predicate < ' tcx > (
350+ pred : ty:: PolyTraitPredicate < ' tcx > ,
351+ cx : & mut DocContext < ' tcx > ,
352+ ) -> Option < WherePredicate > {
353+ // `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
354+ if pred. skip_binder ( ) . constness == ty:: BoundConstness :: ConstIfConst
355+ && Some ( pred. skip_binder ( ) . def_id ( ) ) == cx. tcx . lang_items ( ) . destruct_trait ( )
356+ {
357+ return None ;
362358 }
363- }
364359
365- impl < ' tcx > Clean < ' tcx , Option < WherePredicate > >
366- for ty:: OutlivesPredicate < ty:: Region < ' tcx > , ty:: Region < ' tcx > >
367- {
368- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < WherePredicate > {
369- let ty:: OutlivesPredicate ( a, b) = self ;
360+ let poly_trait_ref = pred. map_bound ( |pred| pred. trait_ref ) ;
361+ Some ( WherePredicate :: BoundPredicate {
362+ ty : clean_middle_ty ( poly_trait_ref. skip_binder ( ) . self_ty ( ) , cx, None ) ,
363+ bounds : vec ! [ poly_trait_ref. clean( cx) ] ,
364+ bound_params : Vec :: new ( ) ,
365+ } )
366+ }
370367
371- if a. is_empty ( ) && b. is_empty ( ) {
372- return None ;
373- }
368+ fn clean_region_outlives_predicate < ' tcx > (
369+ pred : ty:: OutlivesPredicate < ty:: Region < ' tcx > , ty:: Region < ' tcx > > ,
370+ cx : & mut DocContext < ' tcx > ,
371+ ) -> Option < WherePredicate > {
372+ let ty:: OutlivesPredicate ( a, b) = pred;
374373
375- Some ( WherePredicate :: RegionPredicate {
376- lifetime : a. clean ( cx) . expect ( "failed to clean lifetime" ) ,
377- bounds : vec ! [ GenericBound :: Outlives ( b. clean( cx) . expect( "failed to clean bounds" ) ) ] ,
378- } )
374+ if a. is_empty ( ) && b. is_empty ( ) {
375+ return None ;
379376 }
380- }
381377
382- impl < ' tcx > Clean < ' tcx , Option < WherePredicate > >
383- for ty :: OutlivesPredicate < Ty < ' tcx > , ty :: Region < ' tcx > >
384- {
385- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < WherePredicate > {
386- let ty :: OutlivesPredicate ( ty , lt ) = self ;
378+ Some ( WherePredicate :: RegionPredicate {
379+ lifetime : a . clean ( cx ) . expect ( "failed to clean lifetime" ) ,
380+ bounds : vec ! [ GenericBound :: Outlives ( b . clean ( cx ) . expect ( "failed to clean bounds" ) ) ] ,
381+ } )
382+ }
387383
388- if lt. is_empty ( ) {
389- return None ;
390- }
384+ fn clean_type_outlives_predicate < ' tcx > (
385+ pred : ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > ,
386+ cx : & mut DocContext < ' tcx > ,
387+ ) -> Option < WherePredicate > {
388+ let ty:: OutlivesPredicate ( ty, lt) = pred;
391389
392- Some ( WherePredicate :: BoundPredicate {
393- ty : clean_middle_ty ( * ty, cx, None ) ,
394- bounds : vec ! [ GenericBound :: Outlives ( lt. clean( cx) . expect( "failed to clean lifetimes" ) ) ] ,
395- bound_params : Vec :: new ( ) ,
396- } )
390+ if lt. is_empty ( ) {
391+ return None ;
397392 }
393+
394+ Some ( WherePredicate :: BoundPredicate {
395+ ty : clean_middle_ty ( ty, cx, None ) ,
396+ bounds : vec ! [ GenericBound :: Outlives ( lt. clean( cx) . expect( "failed to clean lifetimes" ) ) ] ,
397+ bound_params : Vec :: new ( ) ,
398+ } )
398399}
399400
400401impl < ' tcx > Clean < ' tcx , Term > for ty:: Term < ' tcx > {
@@ -418,10 +419,14 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> {
418419 }
419420}
420421
421- impl < ' tcx > Clean < ' tcx , WherePredicate > for ty:: ProjectionPredicate < ' tcx > {
422- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> WherePredicate {
423- let ty:: ProjectionPredicate { projection_ty, term } = self ;
424- WherePredicate :: EqPredicate { lhs : projection_ty. clean ( cx) , rhs : term. clean ( cx) }
422+ fn clean_projection_predicate < ' tcx > (
423+ pred : ty:: ProjectionPredicate < ' tcx > ,
424+ cx : & mut DocContext < ' tcx > ,
425+ ) -> WherePredicate {
426+ let ty:: ProjectionPredicate { projection_ty, term } = pred;
427+ WherePredicate :: EqPredicate {
428+ lhs : clean_projection ( projection_ty, cx, None ) ,
429+ rhs : term. clean ( cx) ,
425430 }
426431}
427432
@@ -447,12 +452,6 @@ fn clean_projection<'tcx>(
447452 }
448453}
449454
450- impl < ' tcx > Clean < ' tcx , Type > for ty:: ProjectionTy < ' tcx > {
451- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Type {
452- clean_projection ( * self , cx, None )
453- }
454- }
455-
456455fn compute_should_show_cast ( self_def_id : Option < DefId > , trait_ : & Path , self_type : & Type ) -> bool {
457456 !trait_. segments . is_empty ( )
458457 && self_def_id
@@ -734,8 +733,12 @@ fn clean_ty_generics<'tcx>(
734733 . filter ( |b| !b. is_sized_bound ( cx) ) ,
735734 ) ;
736735
737- let proj = projection
738- . map ( |p| ( p. skip_binder ( ) . projection_ty . clean ( cx) , p. skip_binder ( ) . term ) ) ;
736+ let proj = projection. map ( |p| {
737+ (
738+ clean_projection ( p. skip_binder ( ) . projection_ty , cx, None ) ,
739+ p. skip_binder ( ) . term ,
740+ )
741+ } ) ;
739742 if let Some ( ( ( _, trait_did, name) , rhs) ) = proj
740743 . as_ref ( )
741744 . and_then ( |( lhs, rhs) : & ( Type , _ ) | Some ( ( lhs. projection ( ) ?, rhs) ) )
0 commit comments