@@ -116,7 +116,7 @@ pub struct LoweringContext<'a> {
116
116
// When traversing a signature such as `fn foo(x: impl Trait)`,
117
117
// we record `impl Trait` as a new type parameter, then later
118
118
// add it on to `foo`s generics.
119
- in_band_ty_params : Vec < hir:: TyParam > ,
119
+ in_band_ty_params : Vec < hir:: GenericParam > ,
120
120
121
121
// Used to create lifetime definitions from in-band lifetime usages.
122
122
// e.g. `fn foo(x: &'x u8) -> &'x u8` to `fn foo<'x>(x: &'x u8) -> &'x u8`
@@ -695,22 +695,23 @@ impl<'a> LoweringContext<'a> {
695
695
span,
696
696
) ;
697
697
698
- hir:: GenericParam :: Lifetime ( hir:: LifetimeDef {
699
- lifetime : hir:: Lifetime {
700
- id : def_node_id,
701
- span,
702
- name : hir_name,
703
- } ,
704
- bounds : Vec :: new ( ) . into ( ) ,
698
+ hir:: GenericParam {
699
+ id : def_node_id,
700
+ span,
705
701
pure_wrt_drop : false ,
706
- in_band : true ,
707
- } )
702
+ kind : hir:: GenericParamKind :: Lifetime {
703
+ name : hir_name,
704
+ bounds : vec ! [ ] . into ( ) ,
705
+ in_band : true ,
706
+ lifetime_deprecated : hir:: Lifetime {
707
+ id : def_node_id,
708
+ span,
709
+ name : hir_name,
710
+ }
711
+ }
712
+ }
708
713
} )
709
- . chain (
710
- in_band_ty_params
711
- . into_iter ( )
712
- . map ( |tp| hir:: GenericParam :: Type ( tp) ) ,
713
- )
714
+ . chain ( in_band_ty_params. into_iter ( ) )
714
715
. collect ( ) ;
715
716
716
717
( params, res)
@@ -778,12 +779,12 @@ impl<'a> LoweringContext<'a> {
778
779
// This should only be used with generics that have already had their
779
780
// in-band lifetimes added. In practice, this means that this function is
780
781
// only used when lowering a child item of a trait or impl.
781
- fn with_parent_impl_lifetime_defs < T , F > ( & mut self , lt_defs : & [ hir:: LifetimeDef ] , f : F ) -> T
782
+ fn with_parent_impl_lifetime_defs < T , F > ( & mut self , params : & [ hir:: GenericParam ] , f : F ) -> T
782
783
where
783
784
F : FnOnce ( & mut LoweringContext ) -> T ,
784
785
{
785
786
let old_len = self . in_scope_lifetimes . len ( ) ;
786
- let lt_def_names = lt_defs . iter ( ) . map ( |lt_def| lt_def . lifetime . name . name ( ) ) ;
787
+ let lt_def_names = params . iter ( ) . map ( |param| param . name ( ) ) ;
787
788
self . in_scope_lifetimes . extend ( lt_def_names) ;
788
789
789
790
let res = f ( self ) ;
@@ -1252,15 +1253,17 @@ impl<'a> LoweringContext<'a> {
1252
1253
let hir_bounds = self . lower_bounds ( bounds, itctx) ;
1253
1254
// Set the name to `impl Bound1 + Bound2`
1254
1255
let name = Symbol :: intern ( & pprust:: ty_to_string ( t) ) ;
1255
- self . in_band_ty_params . push ( hir:: TyParam {
1256
- name,
1256
+ self . in_band_ty_params . push ( hir:: GenericParam {
1257
1257
id : def_node_id,
1258
- bounds : hir_bounds,
1259
- default : None ,
1260
1258
span,
1261
1259
pure_wrt_drop : false ,
1262
- synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
1263
- attrs : P :: new ( ) ,
1260
+ kind : hir:: GenericParamKind :: Type {
1261
+ name,
1262
+ bounds : hir_bounds,
1263
+ default : None ,
1264
+ synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
1265
+ attrs : P :: new ( ) ,
1266
+ }
1264
1267
} ) ;
1265
1268
1266
1269
hir:: TyPath ( hir:: QPath :: Resolved (
@@ -1367,10 +1370,10 @@ impl<'a> LoweringContext<'a> {
1367
1370
1368
1371
fn visit_generic_param ( & mut self , param : & ' v hir:: GenericParam ) {
1369
1372
// Record the introduction of 'a in `for<'a> ...`
1370
- if let hir:: GenericParam :: Lifetime ( ref lt_def ) = * param {
1373
+ if let hir:: GenericParamKind :: Lifetime { name , .. } = param. kind {
1371
1374
// Introduce lifetimes one at a time so that we can handle
1372
1375
// cases like `fn foo<'d>() -> impl for<'a, 'b: 'a, 'c: 'b + 'd>`
1373
- self . currently_bound_lifetimes . push ( lt_def . lifetime . name ) ;
1376
+ self . currently_bound_lifetimes . push ( name) ;
1374
1377
}
1375
1378
1376
1379
hir:: intravisit:: walk_generic_param ( self , param) ;
@@ -1416,18 +1419,22 @@ impl<'a> LoweringContext<'a> {
1416
1419
Mark :: root ( ) ,
1417
1420
lifetime. span ,
1418
1421
) ;
1419
- let def_lifetime = hir:: Lifetime {
1422
+
1423
+ self . output_lifetime_params . push ( hir:: GenericParam {
1420
1424
id : def_node_id,
1421
1425
span : lifetime. span ,
1422
- name,
1423
- } ;
1424
- self . output_lifetime_params
1425
- . push ( hir:: GenericParam :: Lifetime ( hir:: LifetimeDef {
1426
- lifetime : def_lifetime,
1427
- bounds : Vec :: new ( ) . into ( ) ,
1428
- pure_wrt_drop : false ,
1426
+ pure_wrt_drop : false ,
1427
+ kind : hir:: GenericParamKind :: Lifetime {
1428
+ name,
1429
+ bounds : vec ! [ ] . into ( ) ,
1429
1430
in_band : false ,
1430
- } ) ) ;
1431
+ lifetime_deprecated : hir:: Lifetime {
1432
+ id : def_node_id,
1433
+ span : lifetime. span ,
1434
+ name,
1435
+ }
1436
+ }
1437
+ } ) ;
1431
1438
}
1432
1439
}
1433
1440
}
@@ -1887,47 +1894,6 @@ impl<'a> LoweringContext<'a> {
1887
1894
}
1888
1895
}
1889
1896
1890
- fn lower_ty_param (
1891
- & mut self ,
1892
- tp : & TyParam ,
1893
- add_bounds : & [ TyParamBound ] ,
1894
- itctx : ImplTraitContext ,
1895
- ) -> hir:: TyParam {
1896
- let mut name = self . lower_ident ( tp. ident ) ;
1897
-
1898
- // Don't expose `Self` (recovered "keyword used as ident" parse error).
1899
- // `rustc::ty` expects `Self` to be only used for a trait's `Self`.
1900
- // Instead, use gensym("Self") to create a distinct name that looks the same.
1901
- if name == keywords:: SelfType . name ( ) {
1902
- name = Symbol :: gensym ( "Self" ) ;
1903
- }
1904
-
1905
- let mut bounds = self . lower_bounds ( & tp. bounds , itctx) ;
1906
- if !add_bounds. is_empty ( ) {
1907
- bounds = bounds
1908
- . into_iter ( )
1909
- . chain ( self . lower_bounds ( add_bounds, itctx) . into_iter ( ) )
1910
- . collect ( ) ;
1911
- }
1912
-
1913
- hir:: TyParam {
1914
- id : self . lower_node_id ( tp. id ) . node_id ,
1915
- name,
1916
- bounds,
1917
- default : tp. default
1918
- . as_ref ( )
1919
- . map ( |x| self . lower_ty ( x, ImplTraitContext :: Disallowed ) ) ,
1920
- span : tp. ident . span ,
1921
- pure_wrt_drop : attr:: contains_name ( & tp. attrs , "may_dangle" ) ,
1922
- synthetic : tp. attrs
1923
- . iter ( )
1924
- . filter ( |attr| attr. check_name ( "rustc_synthetic" ) )
1925
- . map ( |_| hir:: SyntheticTyParamKind :: ImplTrait )
1926
- . nth ( 0 ) ,
1927
- attrs : self . lower_attrs ( & tp. attrs ) ,
1928
- }
1929
- }
1930
-
1931
1897
fn lower_lifetime ( & mut self , l : & Lifetime ) -> hir:: Lifetime {
1932
1898
let span = l. ident . span ;
1933
1899
match self . lower_ident ( l. ident ) {
@@ -1962,20 +1928,75 @@ impl<'a> LoweringContext<'a> {
1962
1928
}
1963
1929
}
1964
1930
1965
- fn lower_lifetime_def ( & mut self , l : & LifetimeDef ) -> hir:: LifetimeDef {
1966
- let was_collecting_in_band = self . is_collecting_in_band_lifetimes ;
1967
- self . is_collecting_in_band_lifetimes = false ;
1931
+ fn lower_generic_param ( & mut self ,
1932
+ param : & GenericParamAST ,
1933
+ add_bounds : & NodeMap < Vec < TyParamBound > > ,
1934
+ itctx : ImplTraitContext )
1935
+ -> hir:: GenericParam {
1936
+ match param {
1937
+ GenericParamAST :: Lifetime ( ref lifetime_def) => {
1938
+ let was_collecting_in_band = self . is_collecting_in_band_lifetimes ;
1939
+ self . is_collecting_in_band_lifetimes = false ;
1940
+
1941
+ let lifetime = self . lower_lifetime ( & lifetime_def. lifetime ) ;
1942
+ let param = hir:: GenericParam {
1943
+ id : lifetime. id ,
1944
+ span : lifetime. span ,
1945
+ pure_wrt_drop : attr:: contains_name ( & lifetime_def. attrs , "may_dangle" ) ,
1946
+ kind : hir:: GenericParamKind :: Lifetime {
1947
+ name : lifetime. name ,
1948
+ bounds : lifetime_def. bounds
1949
+ . iter ( )
1950
+ . map ( |lt| self . lower_lifetime ( lt) ) . collect ( ) ,
1951
+ in_band : false ,
1952
+ lifetime_deprecated : lifetime,
1953
+ }
1954
+ } ;
1968
1955
1969
- let def = hir:: LifetimeDef {
1970
- lifetime : self . lower_lifetime ( & l. lifetime ) ,
1971
- bounds : l. bounds . iter ( ) . map ( |l| self . lower_lifetime ( l) ) . collect ( ) ,
1972
- pure_wrt_drop : attr:: contains_name ( & l. attrs , "may_dangle" ) ,
1973
- in_band : false ,
1974
- } ;
1956
+ self . is_collecting_in_band_lifetimes = was_collecting_in_band;
1975
1957
1976
- self . is_collecting_in_band_lifetimes = was_collecting_in_band;
1958
+ param
1959
+ }
1960
+ GenericParamAST :: Type ( ref ty_param) => {
1961
+ let mut name = self . lower_ident ( ty_param. ident ) ;
1962
+
1963
+ // Don't expose `Self` (recovered "keyword used as ident" parse error).
1964
+ // `rustc::ty` expects `Self` to be only used for a trait's `Self`.
1965
+ // Instead, use gensym("Self") to create a distinct name that looks the same.
1966
+ if name == keywords:: SelfType . name ( ) {
1967
+ name = Symbol :: gensym ( "Self" ) ;
1968
+ }
1969
+
1970
+ let mut bounds = self . lower_bounds ( & ty_param. bounds , itctx) ;
1971
+ let add_bounds = add_bounds. get ( & ty_param. id ) . map_or ( & [ ] [ ..] , |x| & x) ;
1972
+ if !add_bounds. is_empty ( ) {
1973
+ bounds = bounds
1974
+ . into_iter ( )
1975
+ . chain ( self . lower_bounds ( add_bounds, itctx) . into_iter ( ) )
1976
+ . collect ( ) ;
1977
+ }
1977
1978
1978
- def
1979
+ hir:: GenericParam {
1980
+ id : self . lower_node_id ( ty_param. id ) . node_id ,
1981
+ span : ty_param. ident . span ,
1982
+ pure_wrt_drop : attr:: contains_name ( & ty_param. attrs , "may_dangle" ) ,
1983
+ kind : hir:: GenericParamKind :: Type {
1984
+ name,
1985
+ bounds,
1986
+ default : ty_param. default . as_ref ( )
1987
+ . map ( |x| {
1988
+ self . lower_ty ( x, ImplTraitContext :: Disallowed )
1989
+ } ) ,
1990
+ synthetic : ty_param. attrs
1991
+ . iter ( )
1992
+ . filter ( |attr| attr. check_name ( "rustc_synthetic" ) )
1993
+ . map ( |_| hir:: SyntheticTyParamKind :: ImplTrait )
1994
+ . nth ( 0 ) ,
1995
+ attrs : self . lower_attrs ( & ty_param. attrs ) ,
1996
+ }
1997
+ }
1998
+ }
1999
+ }
1979
2000
}
1980
2001
1981
2002
fn lower_generic_params (
@@ -1984,19 +2005,7 @@ impl<'a> LoweringContext<'a> {
1984
2005
add_bounds : & NodeMap < Vec < TyParamBound > > ,
1985
2006
itctx : ImplTraitContext ,
1986
2007
) -> hir:: HirVec < hir:: GenericParam > {
1987
- params
1988
- . iter ( )
1989
- . map ( |param| match * param {
1990
- GenericParamAST :: Lifetime ( ref lifetime_def) => {
1991
- hir:: GenericParam :: Lifetime ( self . lower_lifetime_def ( lifetime_def) )
1992
- }
1993
- GenericParamAST :: Type ( ref ty_param) => hir:: GenericParam :: Type ( self . lower_ty_param (
1994
- ty_param,
1995
- add_bounds. get ( & ty_param. id ) . map_or ( & [ ] [ ..] , |x| & x) ,
1996
- itctx,
1997
- ) ) ,
1998
- } )
1999
- . collect ( )
2008
+ params. iter ( ) . map ( |param| self . lower_generic_param ( param, add_bounds, itctx) ) . collect ( )
2000
2009
}
2001
2010
2002
2011
fn lower_generics ( & mut self , g : & Generics , itctx : ImplTraitContext ) -> hir:: Generics {
@@ -2175,8 +2184,8 @@ impl<'a> LoweringContext<'a> {
2175
2184
let trait_ref = self . with_parent_impl_lifetime_defs (
2176
2185
& bound_generic_params
2177
2186
. iter ( )
2178
- . filter_map ( |p | match * p {
2179
- hir:: GenericParam :: Lifetime ( ref ld ) => Some ( ld . clone ( ) ) ,
2187
+ . filter_map ( |param | match param . kind {
2188
+ hir:: GenericParamKind :: Lifetime { .. } => Some ( param . clone ( ) ) ,
2180
2189
_ => None ,
2181
2190
} )
2182
2191
. collect :: < Vec < _ > > ( ) ,
0 commit comments