@@ -506,32 +506,31 @@ fn clean_generic_param_def<'tcx>(
506
506
) -> GenericParamDef {
507
507
let ( name, kind) = match def. kind {
508
508
ty:: GenericParamDefKind :: Lifetime => {
509
- ( def. name , GenericParamDefKind :: Lifetime { outlives : ThinVec :: new ( ) } )
509
+ ( def. name , LifetimeParam { outlives : ThinVec :: new ( ) } . into ( ) )
510
510
}
511
511
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 (
514
514
ty:: Binder :: dummy ( cx. tcx . type_of ( def. def_id ) . instantiate_identity ( ) ) ,
515
515
cx,
516
516
Some ( def. def_id ) ,
517
517
None ,
518
- ) )
519
- } else {
520
- None
521
- } ;
518
+ )
519
+ } ) ;
522
520
(
523
521
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,
527
525
synthetic,
528
- } ,
526
+ }
527
+ . into ( ) ,
529
528
)
530
529
}
531
530
ty:: GenericParamDefKind :: Const { has_default, is_host_effect } => (
532
531
def. name ,
533
- GenericParamDefKind :: Const {
534
- ty : Box :: new ( clean_middle_ty (
532
+ ConstParam {
533
+ ty : clean_middle_ty (
535
534
ty:: Binder :: dummy (
536
535
cx. tcx
537
536
. type_of ( def. def_id )
@@ -541,15 +540,13 @@ fn clean_generic_param_def<'tcx>(
541
540
cx,
542
541
Some ( def. def_id ) ,
543
542
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
+ } ) ,
551
547
is_host_effect,
552
- } ,
548
+ }
549
+ . into ( ) ,
553
550
) ,
554
551
} ;
555
552
@@ -576,7 +573,7 @@ fn clean_generic_param<'tcx>(
576
573
} else {
577
574
ThinVec :: new ( )
578
575
} ;
579
- ( param. name . ident ( ) . name , GenericParamDefKind :: Lifetime { outlives } )
576
+ ( param. name . ident ( ) . name , LifetimeParam { outlives } . into ( ) )
580
577
}
581
578
hir:: GenericParamKind :: Type { ref default, synthetic } => {
582
579
let bounds = if let Some ( generics) = generics {
@@ -591,21 +588,18 @@ fn clean_generic_param<'tcx>(
591
588
} ;
592
589
(
593
590
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 ( ) ,
599
592
)
600
593
}
601
594
hir:: GenericParamKind :: Const { ty, default, is_host_effect } => (
602
595
param. name . ident ( ) . name ,
603
- GenericParamDefKind :: Const {
604
- ty : Box :: new ( clean_ty ( ty, cx) ) ,
596
+ ConstParam {
597
+ ty : clean_ty ( ty, cx) ,
605
598
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 ( ) ) ,
607
600
is_host_effect,
608
- } ,
601
+ }
602
+ . into ( ) ,
609
603
) ,
610
604
} ;
611
605
@@ -643,8 +637,8 @@ pub(crate) fn clean_generics<'tcx>(
643
637
. filter ( |param| is_impl_trait ( param) )
644
638
. map ( |param| {
645
639
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 ( ) ) ;
648
642
param
649
643
} )
650
644
. collect :: < Vec < _ > > ( ) ;
@@ -702,21 +696,21 @@ pub(crate) fn clean_generics<'tcx>(
702
696
for param in generics. params . iter ( ) . filter ( |p| !is_impl_trait ( p) && !is_elided_lifetime ( p) ) {
703
697
let mut param = clean_generic_param ( cx, Some ( generics) , param) ;
704
698
match & mut param. kind {
705
- GenericParamDefKind :: Lifetime { outlives } => {
699
+ GenericParamDefKind :: Lifetime ( lt_param ) => {
706
700
if let Some ( region_pred) = region_predicates. get_mut ( & Lifetime ( param. name ) ) {
707
701
// We merge bounds in the `where` clause.
708
- for outlive in outlives. drain ( ..) {
702
+ for outlive in lt_param . outlives . drain ( ..) {
709
703
let outlive = GenericBound :: Outlives ( outlive) ;
710
704
if !region_pred. contains ( & outlive) {
711
705
region_pred. push ( outlive) ;
712
706
}
713
707
}
714
708
}
715
709
}
716
- GenericParamDefKind :: Type { bounds , synthetic : false , .. } => {
710
+ GenericParamDefKind :: Type ( ty_param ) if !ty_param . synthetic => {
717
711
if let Some ( bound_pred) = bound_predicates. get_mut ( & Type :: Generic ( param. name ) ) {
718
712
// We merge bounds in the `where` clause.
719
- for bound in bounds. drain ( ..) {
713
+ for bound in ty_param . bounds . drain ( ..) {
720
714
if !bound_pred. 0 . contains ( & bound) {
721
715
bound_pred. 0 . push ( bound) ;
722
716
}
@@ -1063,17 +1057,15 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib
1063
1057
for ( pos, literal) in meta_item_list. iter ( ) . filter_map ( |meta| meta. lit ( ) ) . enumerate ( ) {
1064
1058
match literal. kind {
1065
1059
ast:: LitKind :: Int ( a, _) => {
1066
- let gen = func. generics . params . remove ( 0 ) ;
1060
+ let param = func. generics . params . remove ( 0 ) ;
1067
1061
if let GenericParamDef {
1068
- name,
1069
- kind : GenericParamDefKind :: Const { ty, .. } ,
1070
- ..
1071
- } = gen
1062
+ name, kind : GenericParamDefKind :: Const ( param) , ..
1063
+ } = param
1072
1064
{
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
+ ) ;
1077
1069
} else {
1078
1070
panic ! ( "unexpected non const in position {pos}" ) ;
1079
1071
}
@@ -3149,11 +3141,8 @@ fn clean_bound_vars<'tcx>(
3149
3141
Some ( GenericParamDef {
3150
3142
name,
3151
3143
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 ( ) ,
3157
3146
} )
3158
3147
}
3159
3148
// FIXME(non_lifetime_binders): Support higher-ranked const parameters.
0 commit comments