@@ -398,23 +398,19 @@ fn clean_type_outlives_predicate<'tcx>(
398398 } )
399399}
400400
401- impl < ' tcx > Clean < ' tcx , Term > for ty:: Term < ' tcx > {
402- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Term {
403- match self {
404- ty:: Term :: Ty ( ty) => Term :: Type ( clean_middle_ty ( * ty, cx, None ) ) ,
405- ty:: Term :: Const ( c) => Term :: Constant ( clean_middle_const ( * c, cx) ) ,
406- }
401+ fn clean_middle_term < ' tcx > ( term : ty:: Term < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Term {
402+ match term {
403+ ty:: Term :: Ty ( ty) => Term :: Type ( clean_middle_ty ( ty, cx, None ) ) ,
404+ ty:: Term :: Const ( c) => Term :: Constant ( clean_middle_const ( c, cx) ) ,
407405 }
408406}
409407
410- impl < ' tcx > Clean < ' tcx , Term > for hir:: Term < ' tcx > {
411- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Term {
412- match self {
413- hir:: Term :: Ty ( ty) => Term :: Type ( clean_ty ( ty, cx) ) ,
414- hir:: Term :: Const ( c) => {
415- let def_id = cx. tcx . hir ( ) . local_def_id ( c. hir_id ) ;
416- Term :: Constant ( clean_middle_const ( ty:: Const :: from_anon_const ( cx. tcx , def_id) , cx) )
417- }
408+ fn clean_hir_term < ' tcx > ( term : & hir:: Term < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Term {
409+ match term {
410+ hir:: Term :: Ty ( ty) => Term :: Type ( clean_ty ( ty, cx) ) ,
411+ hir:: Term :: Const ( c) => {
412+ let def_id = cx. tcx . hir ( ) . local_def_id ( c. hir_id ) ;
413+ Term :: Constant ( clean_middle_const ( ty:: Const :: from_anon_const ( cx. tcx , def_id) , cx) )
418414 }
419415 }
420416}
@@ -426,7 +422,7 @@ fn clean_projection_predicate<'tcx>(
426422 let ty:: ProjectionPredicate { projection_ty, term } = pred;
427423 WherePredicate :: EqPredicate {
428424 lhs : clean_projection ( projection_ty, cx, None ) ,
429- rhs : term . clean ( cx) ,
425+ rhs : clean_middle_term ( term , cx) ,
430426 }
431427}
432428
@@ -474,47 +470,44 @@ fn projection_to_path_segment<'tcx>(
474470 }
475471}
476472
477- impl < ' tcx > Clean < ' tcx , GenericParamDef > for ty:: GenericParamDef {
478- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> GenericParamDef {
479- let ( name, kind) = match self . kind {
480- ty:: GenericParamDefKind :: Lifetime => {
481- ( self . name , GenericParamDefKind :: Lifetime { outlives : vec ! [ ] } )
482- }
483- ty:: GenericParamDefKind :: Type { has_default, synthetic, .. } => {
484- let default = if has_default {
485- Some ( clean_middle_ty ( cx. tcx . type_of ( self . def_id ) , cx, Some ( self . def_id ) ) )
486- } else {
487- None
488- } ;
489- (
490- self . name ,
491- GenericParamDefKind :: Type {
492- did : self . def_id ,
493- bounds : vec ! [ ] , // These are filled in from the where-clauses.
494- default : default. map ( Box :: new) ,
495- synthetic,
496- } ,
497- )
498- }
499- ty:: GenericParamDefKind :: Const { has_default } => (
500- self . name ,
501- GenericParamDefKind :: Const {
502- did : self . def_id ,
503- ty : Box :: new ( clean_middle_ty (
504- cx. tcx . type_of ( self . def_id ) ,
505- cx,
506- Some ( self . def_id ) ,
507- ) ) ,
508- default : match has_default {
509- true => Some ( Box :: new ( cx. tcx . const_param_default ( self . def_id ) . to_string ( ) ) ) ,
510- false => None ,
511- } ,
473+ fn clean_generic_param_def < ' tcx > (
474+ def : & ty:: GenericParamDef ,
475+ cx : & mut DocContext < ' tcx > ,
476+ ) -> GenericParamDef {
477+ let ( name, kind) = match def. kind {
478+ ty:: GenericParamDefKind :: Lifetime => {
479+ ( def. name , GenericParamDefKind :: Lifetime { outlives : vec ! [ ] } )
480+ }
481+ ty:: GenericParamDefKind :: Type { has_default, synthetic, .. } => {
482+ let default = if has_default {
483+ Some ( clean_middle_ty ( cx. tcx . type_of ( def. def_id ) , cx, Some ( def. def_id ) ) )
484+ } else {
485+ None
486+ } ;
487+ (
488+ def. name ,
489+ GenericParamDefKind :: Type {
490+ did : def. def_id ,
491+ bounds : vec ! [ ] , // These are filled in from the where-clauses.
492+ default : default. map ( Box :: new) ,
493+ synthetic,
512494 } ,
513- ) ,
514- } ;
495+ )
496+ }
497+ ty:: GenericParamDefKind :: Const { has_default } => (
498+ def. name ,
499+ GenericParamDefKind :: Const {
500+ did : def. def_id ,
501+ ty : Box :: new ( clean_middle_ty ( cx. tcx . type_of ( def. def_id ) , cx, Some ( def. def_id ) ) ) ,
502+ default : match has_default {
503+ true => Some ( Box :: new ( cx. tcx . const_param_default ( def. def_id ) . to_string ( ) ) ) ,
504+ false => None ,
505+ } ,
506+ } ,
507+ ) ,
508+ } ;
515509
516- GenericParamDef { name, kind }
517- }
510+ GenericParamDef { name, kind }
518511}
519512
520513fn clean_generic_param < ' tcx > (
@@ -672,7 +665,7 @@ fn clean_ty_generics<'tcx>(
672665 . iter ( )
673666 . filter_map ( |param| match param. kind {
674667 ty:: GenericParamDefKind :: Lifetime if param. name == kw:: UnderscoreLifetime => None ,
675- ty:: GenericParamDefKind :: Lifetime => Some ( param . clean ( cx) ) ,
668+ ty:: GenericParamDefKind :: Lifetime => Some ( clean_generic_param_def ( param , cx) ) ,
676669 ty:: GenericParamDefKind :: Type { synthetic, .. } => {
677670 if param. name == kw:: SelfUpper {
678671 assert_eq ! ( param. index, 0 ) ;
@@ -682,9 +675,9 @@ fn clean_ty_generics<'tcx>(
682675 impl_trait. insert ( param. index . into ( ) , vec ! [ ] ) ;
683676 return None ;
684677 }
685- Some ( param . clean ( cx) )
678+ Some ( clean_generic_param_def ( param , cx) )
686679 }
687- ty:: GenericParamDefKind :: Const { .. } => Some ( param . clean ( cx) ) ,
680+ ty:: GenericParamDefKind :: Const { .. } => Some ( clean_generic_param_def ( param , cx) ) ,
688681 } )
689682 . collect :: < Vec < GenericParamDef > > ( ) ;
690683
@@ -1682,7 +1675,9 @@ pub(crate) fn clean_middle_ty<'tcx>(
16821675 . projection_ty ,
16831676 cx,
16841677 ) ,
1685- kind : TypeBindingKind :: Equality { term : pb. skip_binder ( ) . term . clean ( cx) } ,
1678+ kind : TypeBindingKind :: Equality {
1679+ term : clean_middle_term ( pb. skip_binder ( ) . term , cx) ,
1680+ } ,
16861681 } ) ;
16871682 }
16881683
@@ -1746,7 +1741,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
17461741 Some ( TypeBinding {
17471742 assoc : projection_to_path_segment ( proj. projection_ty , cx) ,
17481743 kind : TypeBindingKind :: Equality {
1749- term : proj. term . clean ( cx) ,
1744+ term : clean_middle_term ( proj. term , cx) ,
17501745 } ,
17511746 } )
17521747 } else {
@@ -2283,7 +2278,7 @@ impl<'tcx> Clean<'tcx, TypeBindingKind> for hir::TypeBindingKind<'tcx> {
22832278 fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> TypeBindingKind {
22842279 match * self {
22852280 hir:: TypeBindingKind :: Equality { ref term } => {
2286- TypeBindingKind :: Equality { term : term . clean ( cx) }
2281+ TypeBindingKind :: Equality { term : clean_hir_term ( term , cx) }
22872282 }
22882283 hir:: TypeBindingKind :: Constraint { bounds } => TypeBindingKind :: Constraint {
22892284 bounds : bounds. iter ( ) . filter_map ( |b| b. clean ( cx) ) . collect ( ) ,
0 commit comments