@@ -506,32 +506,31 @@ fn clean_generic_param_def<'tcx>(
506506) -> GenericParamDef {
507507 let ( name, kind) = match def. kind {
508508 ty:: GenericParamDefKind :: Lifetime => {
509- ( def. name , GenericParamDefKind :: Lifetime { outlives : ThinVec :: new ( ) } )
509+ ( def. name , LifetimeParam { outlives : ThinVec :: new ( ) } . into ( ) )
510510 }
511511 ty:: GenericParamDefKind :: Type { has_default, synthetic, .. } => {
512- let default = if has_default {
513- Some ( clean_middle_ty (
512+ let default = has_default. then ( || {
513+ clean_middle_ty (
514514 ty:: Binder :: dummy ( cx. tcx . type_of ( def. def_id ) . instantiate_identity ( ) ) ,
515515 cx,
516516 Some ( def. def_id ) ,
517517 None ,
518- ) )
519- } else {
520- None
521- } ;
518+ )
519+ } ) ;
522520 (
523521 def. name ,
524- GenericParamDefKind :: Type {
525- bounds : ThinVec :: new ( ) , // These are filled in from the where-clauses .
526- default : default . map ( Box :: new ) ,
522+ TypeParam {
523+ bounds : ThinVec :: new ( ) , // These are filled in from the where-clause .
524+ default,
527525 synthetic,
528- } ,
526+ }
527+ . into ( ) ,
529528 )
530529 }
531530 ty:: GenericParamDefKind :: Const { has_default, is_host_effect } => (
532531 def. name ,
533- GenericParamDefKind :: Const {
534- ty : Box :: new ( clean_middle_ty (
532+ ConstParam {
533+ ty : clean_middle_ty (
535534 ty:: Binder :: dummy (
536535 cx. tcx
537536 . type_of ( def. def_id )
@@ -541,15 +540,13 @@ fn clean_generic_param_def<'tcx>(
541540 cx,
542541 Some ( def. def_id ) ,
543542 None ,
544- ) ) ,
545- default : match has_default {
546- true => Some ( Box :: new (
547- cx. tcx . const_param_default ( def. def_id ) . instantiate_identity ( ) . to_string ( ) ,
548- ) ) ,
549- false => None ,
550- } ,
543+ ) ,
544+ default : has_default. then ( || {
545+ cx. tcx . const_param_default ( def. def_id ) . instantiate_identity ( ) . to_string ( )
546+ } ) ,
551547 is_host_effect,
552- } ,
548+ }
549+ . into ( ) ,
553550 ) ,
554551 } ;
555552
@@ -576,7 +573,7 @@ fn clean_generic_param<'tcx>(
576573 } else {
577574 ThinVec :: new ( )
578575 } ;
579- ( param. name . ident ( ) . name , GenericParamDefKind :: Lifetime { outlives } )
576+ ( param. name . ident ( ) . name , LifetimeParam { outlives } . into ( ) )
580577 }
581578 hir:: GenericParamKind :: Type { ref default, synthetic } => {
582579 let bounds = if let Some ( generics) = generics {
@@ -591,21 +588,18 @@ fn clean_generic_param<'tcx>(
591588 } ;
592589 (
593590 param. name . ident ( ) . name ,
594- GenericParamDefKind :: Type {
595- bounds,
596- default : default. map ( |t| clean_ty ( t, cx) ) . map ( Box :: new) ,
597- synthetic,
598- } ,
591+ TypeParam { bounds, default : default. map ( |t| clean_ty ( t, cx) ) , synthetic } . into ( ) ,
599592 )
600593 }
601594 hir:: GenericParamKind :: Const { ty, default, is_host_effect } => (
602595 param. name . ident ( ) . name ,
603- GenericParamDefKind :: Const {
604- ty : Box :: new ( clean_ty ( ty, cx) ) ,
596+ ConstParam {
597+ ty : clean_ty ( ty, cx) ,
605598 default : default
606- . map ( |ct| Box :: new ( ty:: Const :: from_anon_const ( cx. tcx , ct. def_id ) . to_string ( ) ) ) ,
599+ . map ( |ct| ty:: Const :: from_anon_const ( cx. tcx , ct. def_id ) . to_string ( ) ) ,
607600 is_host_effect,
608- } ,
601+ }
602+ . into ( ) ,
609603 ) ,
610604 } ;
611605
@@ -643,8 +637,8 @@ pub(crate) fn clean_generics<'tcx>(
643637 . filter ( |param| is_impl_trait ( param) )
644638 . map ( |param| {
645639 let param = clean_generic_param ( cx, Some ( generics) , param) ;
646- let GenericParamDefKind :: Type { bounds , .. } = & param. kind else { unreachable ! ( ) } ;
647- cx. impl_trait_bounds . insert ( param. def_id . into ( ) , bounds. to_vec ( ) ) ;
640+ let GenericParamDefKind :: Type ( ty_param ) = & param. kind else { unreachable ! ( ) } ;
641+ cx. impl_trait_bounds . insert ( param. def_id . into ( ) , ty_param . bounds . to_vec ( ) ) ;
648642 param
649643 } )
650644 . collect :: < Vec < _ > > ( ) ;
@@ -702,21 +696,21 @@ pub(crate) fn clean_generics<'tcx>(
702696 for param in generics. params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
703697 let mut param = clean_generic_param ( cx, Some ( generics) , param) ;
704698 match & mut param. kind {
705- GenericParamDefKind :: Lifetime { outlives } => {
699+ GenericParamDefKind :: Lifetime ( lt_param ) => {
706700 if let Some ( region_pred) = region_predicates. get_mut ( & Lifetime ( param. name ) ) {
707701 // We merge bounds in the `where` clause.
708- for outlive in outlives. drain ( ..) {
702+ for outlive in lt_param . outlives . drain ( ..) {
709703 let outlive = GenericBound :: Outlives ( outlive) ;
710704 if !region_pred. contains ( & outlive) {
711705 region_pred. push ( outlive) ;
712706 }
713707 }
714708 }
715709 }
716- GenericParamDefKind :: Type { bounds , synthetic : false , .. } => {
710+ GenericParamDefKind :: Type ( ty_param ) if !ty_param . synthetic => {
717711 if let Some ( bound_pred) = bound_predicates. get_mut ( & Type :: Generic ( param. name ) ) {
718712 // We merge bounds in the `where` clause.
719- for bound in bounds. drain ( ..) {
713+ for bound in ty_param . bounds . drain ( ..) {
720714 if !bound_pred. 0 . contains ( & bound) {
721715 bound_pred. 0 . push ( bound) ;
722716 }
@@ -1063,17 +1057,15 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib
10631057 for ( pos, literal) in meta_item_list. iter ( ) . filter_map ( |meta| meta. lit ( ) ) . enumerate ( ) {
10641058 match literal. kind {
10651059 ast:: LitKind :: Int ( a, _) => {
1066- let gen = func. generics . params . remove ( 0 ) ;
1060+ let param = func. generics . params . remove ( 0 ) ;
10671061 if let GenericParamDef {
1068- name,
1069- kind : GenericParamDefKind :: Const { ty, .. } ,
1070- ..
1071- } = gen
1062+ name, kind : GenericParamDefKind :: Const ( param) , ..
1063+ } = param
10721064 {
1073- func. decl
1074- . inputs
1075- . values
1076- . insert ( a . get ( ) as _ , Argument { name , type_ : * ty , is_const : true } ) ;
1065+ func. decl . inputs . values . insert (
1066+ a . get ( ) as _ ,
1067+ Argument { name , type_ : param . ty , is_const : true } ,
1068+ ) ;
10771069 } else {
10781070 panic ! ( "unexpected non const in position {pos}" ) ;
10791071 }
@@ -3149,11 +3141,8 @@ fn clean_bound_vars<'tcx>(
31493141 Some ( GenericParamDef {
31503142 name,
31513143 def_id,
3152- kind : GenericParamDefKind :: Type {
3153- bounds : ThinVec :: new ( ) ,
3154- default : None ,
3155- synthetic : false ,
3156- } ,
3144+ kind : TypeParam { bounds : ThinVec :: new ( ) , default : None , synthetic : false }
3145+ . into ( ) ,
31573146 } )
31583147 }
31593148 // FIXME(non_lifetime_binders): Support higher-ranked const parameters.
0 commit comments