@@ -382,17 +382,9 @@ impl<'a> LoweringContext<'a> {
382
382
let item_lifetimes = match self . lctx . items . get ( & item. id ) . unwrap ( ) . node {
383
383
hir:: Item_ :: ItemImpl ( _, _, _, ref generics, ..)
384
384
| hir:: Item_ :: ItemTrait ( _, _, ref generics, ..) => {
385
- generics. params
386
- . iter ( )
387
- . filter_map ( |param| match param. kind {
388
- hir:: GenericParamKind :: Lifetime { .. } => {
389
- Some ( param. clone ( ) )
390
- }
391
- _ => None ,
392
- } )
393
- . collect :: < Vec < _ > > ( )
385
+ generics. params . clone ( )
394
386
}
395
- _ => Vec :: new ( ) ,
387
+ _ => HirVec :: new ( ) ,
396
388
} ;
397
389
398
390
self . lctx . with_parent_impl_lifetime_defs ( & item_lifetimes, |this| {
@@ -766,16 +758,15 @@ impl<'a> LoweringContext<'a> {
766
758
// This is used to track which lifetimes have already been defined, and
767
759
// which are new in-band lifetimes that need to have a definition created
768
760
// for them.
769
- fn with_in_scope_lifetime_defs < ' l , T , F > (
770
- & mut self ,
771
- params : impl Iterator < Item = & ' l GenericParamAST > ,
772
- f : F ,
773
- ) -> T
761
+ fn with_in_scope_lifetime_defs < T , F > ( & mut self , params : & Vec < GenericParamAST > , f : F ) -> T
774
762
where
775
763
F : FnOnce ( & mut LoweringContext ) -> T ,
776
764
{
777
765
let old_len = self . in_scope_lifetimes . len ( ) ;
778
- let lt_def_names = params. map ( |param| param. ident . name ) ;
766
+ let lt_def_names = params. iter ( ) . filter_map ( |param| match param. kind {
767
+ GenericParamKindAST :: Lifetime { .. } => Some ( param. ident . name ) ,
768
+ _ => None ,
769
+ } ) ;
779
770
self . in_scope_lifetimes . extend ( lt_def_names) ;
780
771
781
772
let res = f ( self ) ;
@@ -789,12 +780,17 @@ impl<'a> LoweringContext<'a> {
789
780
// This should only be used with generics that have already had their
790
781
// in-band lifetimes added. In practice, this means that this function is
791
782
// only used when lowering a child item of a trait or impl.
792
- fn with_parent_impl_lifetime_defs < T , F > ( & mut self , params : & [ hir:: GenericParam ] , f : F ) -> T
793
- where
783
+ fn with_parent_impl_lifetime_defs < T , F > ( & mut self ,
784
+ params : & HirVec < hir:: GenericParam > ,
785
+ f : F
786
+ ) -> T where
794
787
F : FnOnce ( & mut LoweringContext ) -> T ,
795
788
{
796
789
let old_len = self . in_scope_lifetimes . len ( ) ;
797
- let lt_def_names = params. iter ( ) . map ( |param| param. name ( ) ) ;
790
+ let lt_def_names = params. iter ( ) . filter_map ( |param| match param. kind {
791
+ hir:: GenericParamKind :: Lifetime { .. } => Some ( param. name ( ) ) ,
792
+ _ => None ,
793
+ } ) ;
798
794
self . in_scope_lifetimes . extend ( lt_def_names) ;
799
795
800
796
let res = f ( self ) ;
@@ -820,10 +816,7 @@ impl<'a> LoweringContext<'a> {
820
816
F : FnOnce ( & mut LoweringContext ) -> T ,
821
817
{
822
818
let ( in_band_defs, ( mut lowered_generics, res) ) = self . with_in_scope_lifetime_defs (
823
- generics. params . iter ( ) . filter_map ( |param| match param. kind {
824
- GenericParamKindAST :: Lifetime { .. } => Some ( param) ,
825
- _ => None ,
826
- } ) ,
819
+ & generics. params ,
827
820
|this| {
828
821
let itctx = ImplTraitContext :: Universal ( parent_id) ;
829
822
this. collect_in_band_defs ( parent_id, anonymous_lifetime_mode, |this| {
@@ -1051,16 +1044,12 @@ impl<'a> LoweringContext<'a> {
1051
1044
}
1052
1045
1053
1046
fn lower_generic_arg ( & mut self ,
1054
- p : & ast:: GenericArgAST ,
1047
+ arg : & ast:: GenericArgAST ,
1055
1048
itctx : ImplTraitContext )
1056
1049
-> hir:: GenericArg {
1057
- match p {
1058
- ast:: GenericArgAST :: Lifetime ( lt) => {
1059
- GenericArg :: Lifetime ( self . lower_lifetime ( & lt) )
1060
- }
1061
- ast:: GenericArgAST :: Type ( ty) => {
1062
- GenericArg :: Type ( self . lower_ty ( & ty, itctx) )
1063
- }
1050
+ match arg {
1051
+ ast:: GenericArgAST :: Lifetime ( lt) => GenericArg :: Lifetime ( self . lower_lifetime ( & lt) ) ,
1052
+ ast:: GenericArgAST :: Type ( ty) => GenericArg :: Type ( self . lower_ty ( & ty, itctx) ) ,
1064
1053
}
1065
1054
}
1066
1055
@@ -1079,10 +1068,7 @@ impl<'a> LoweringContext<'a> {
1079
1068
hir:: TyRptr ( lifetime, self . lower_mt ( mt, itctx) )
1080
1069
}
1081
1070
TyKind :: BareFn ( ref f) => self . with_in_scope_lifetime_defs (
1082
- f. generic_params . iter ( ) . filter_map ( |param| match param. kind {
1083
- GenericParamKindAST :: Lifetime { .. } => Some ( param) ,
1084
- _ => None ,
1085
- } ) ,
1071
+ & f. generic_params ,
1086
1072
|this| {
1087
1073
this. with_anonymous_lifetime_mode (
1088
1074
AnonymousLifetimeMode :: PassThrough ,
@@ -1946,6 +1932,15 @@ impl<'a> LoweringContext<'a> {
1946
1932
}
1947
1933
}
1948
1934
1935
+ fn lower_generic_params (
1936
+ & mut self ,
1937
+ params : & Vec < GenericParamAST > ,
1938
+ add_bounds : & NodeMap < Vec < TyParamBound > > ,
1939
+ itctx : ImplTraitContext ,
1940
+ ) -> hir:: HirVec < hir:: GenericParam > {
1941
+ params. iter ( ) . map ( |param| self . lower_generic_param ( param, add_bounds, itctx) ) . collect ( )
1942
+ }
1943
+
1949
1944
fn lower_generic_param ( & mut self ,
1950
1945
param : & GenericParamAST ,
1951
1946
add_bounds : & NodeMap < Vec < TyParamBound > > ,
@@ -1986,10 +1981,9 @@ impl<'a> LoweringContext<'a> {
1986
1981
let mut bounds = self . lower_bounds ( bounds, itctx) ;
1987
1982
let add_bounds = add_bounds. get ( & param. id ) . map_or ( & [ ] [ ..] , |x| & x) ;
1988
1983
if !add_bounds. is_empty ( ) {
1989
- bounds = bounds
1990
- . into_iter ( )
1991
- . chain ( self . lower_bounds ( add_bounds, itctx) . into_iter ( ) )
1992
- . collect ( ) ;
1984
+ bounds = bounds. into_iter ( )
1985
+ . chain ( self . lower_bounds ( add_bounds, itctx) . into_iter ( ) )
1986
+ . collect ( ) ;
1993
1987
}
1994
1988
1995
1989
hir:: GenericParam {
@@ -2005,23 +1999,14 @@ impl<'a> LoweringContext<'a> {
2005
1999
synthetic : param. attrs . iter ( )
2006
2000
. filter ( |attr| attr. check_name ( "rustc_synthetic" ) )
2007
2001
. map ( |_| hir:: SyntheticTyParamKind :: ImplTrait )
2008
- . nth ( 0 ) ,
2002
+ . next ( ) ,
2009
2003
attrs : self . lower_attrs ( & param. attrs ) ,
2010
2004
}
2011
2005
}
2012
2006
}
2013
2007
}
2014
2008
}
2015
2009
2016
- fn lower_generic_params (
2017
- & mut self ,
2018
- params : & Vec < GenericParamAST > ,
2019
- add_bounds : & NodeMap < Vec < TyParamBound > > ,
2020
- itctx : ImplTraitContext ,
2021
- ) -> hir:: HirVec < hir:: GenericParam > {
2022
- params. iter ( ) . map ( |param| self . lower_generic_param ( param, add_bounds, itctx) ) . collect ( )
2023
- }
2024
-
2025
2010
fn lower_generics (
2026
2011
& mut self ,
2027
2012
generics : & Generics ,
@@ -2107,10 +2092,7 @@ impl<'a> LoweringContext<'a> {
2107
2092
span,
2108
2093
} ) => {
2109
2094
self . with_in_scope_lifetime_defs (
2110
- bound_generic_params. iter ( ) . filter_map ( |param| match param. kind {
2111
- GenericParamKindAST :: Lifetime { .. } => Some ( param) ,
2112
- _ => None ,
2113
- } ) ,
2095
+ & bound_generic_params,
2114
2096
|this| {
2115
2097
hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
2116
2098
bound_generic_params : this. lower_generic_params (
@@ -2203,13 +2185,7 @@ impl<'a> LoweringContext<'a> {
2203
2185
let bound_generic_params =
2204
2186
self . lower_generic_params ( & p. bound_generic_params , & NodeMap ( ) , itctx) ;
2205
2187
let trait_ref = self . with_parent_impl_lifetime_defs (
2206
- & bound_generic_params
2207
- . iter ( )
2208
- . filter_map ( |param| match param. kind {
2209
- hir:: GenericParamKind :: Lifetime { .. } => Some ( param. clone ( ) ) ,
2210
- _ => None ,
2211
- } )
2212
- . collect :: < Vec < _ > > ( ) ,
2188
+ & bound_generic_params,
2213
2189
|this| this. lower_trait_ref ( & p. trait_ref , itctx) ,
2214
2190
) ;
2215
2191
@@ -2426,10 +2402,7 @@ impl<'a> LoweringContext<'a> {
2426
2402
) ;
2427
2403
2428
2404
let new_impl_items = self . with_in_scope_lifetime_defs (
2429
- ast_generics. params . iter ( ) . filter_map ( |param| match param. kind {
2430
- GenericParamKindAST :: Lifetime { .. } => Some ( param) ,
2431
- _ => None ,
2432
- } ) ,
2405
+ & ast_generics. params ,
2433
2406
|this| {
2434
2407
impl_items
2435
2408
. iter ( )
0 commit comments