@@ -759,20 +759,20 @@ impl<'a> LoweringContext<'a> {
759
759
hir_name
760
760
}
761
761
762
- // Evaluates `f` with the lifetimes in `lt_defs ` in-scope.
762
+ // Evaluates `f` with the lifetimes in `params ` in-scope.
763
763
// This is used to track which lifetimes have already been defined, and
764
764
// which are new in-band lifetimes that need to have a definition created
765
765
// for them.
766
766
fn with_in_scope_lifetime_defs < ' l , T , F > (
767
767
& mut self ,
768
- lt_defs : impl Iterator < Item = & ' l LifetimeDef > ,
768
+ params : impl Iterator < Item = & ' l GenericParamAST > ,
769
769
f : F ,
770
770
) -> T
771
771
where
772
772
F : FnOnce ( & mut LoweringContext ) -> T ,
773
773
{
774
774
let old_len = self . in_scope_lifetimes . len ( ) ;
775
- let lt_def_names = lt_defs . map ( |lt_def| lt_def . lifetime . ident . name ) ;
775
+ let lt_def_names = params . map ( |param| param . ident . name ) ;
776
776
self . in_scope_lifetimes . extend ( lt_def_names) ;
777
777
778
778
let res = f ( self ) ;
@@ -781,8 +781,8 @@ impl<'a> LoweringContext<'a> {
781
781
res
782
782
}
783
783
784
- // Same as the method above, but accepts `hir::LifetimeDef `s
785
- // instead of `ast::LifetimeDef `s.
784
+ // Same as the method above, but accepts `hir::GenericParam `s
785
+ // instead of `ast::GenericParam `s.
786
786
// This should only be used with generics that have already had their
787
787
// in-band lifetimes added. In practice, this means that this function is
788
788
// only used when lowering a child item of a trait or impl.
@@ -817,8 +817,8 @@ impl<'a> LoweringContext<'a> {
817
817
F : FnOnce ( & mut LoweringContext ) -> T ,
818
818
{
819
819
let ( in_band_defs, ( mut lowered_generics, res) ) = self . with_in_scope_lifetime_defs (
820
- generics. params . iter ( ) . filter_map ( |p | match p {
821
- GenericParamAST :: Lifetime ( ld ) => Some ( ld ) ,
820
+ generics. params . iter ( ) . filter_map ( |param | match param . kind {
821
+ GenericParamKindAST :: Lifetime { .. } => Some ( param ) ,
822
822
_ => None ,
823
823
} ) ,
824
824
|this| {
@@ -1076,8 +1076,8 @@ impl<'a> LoweringContext<'a> {
1076
1076
hir:: TyRptr ( lifetime, self . lower_mt ( mt, itctx) )
1077
1077
}
1078
1078
TyKind :: BareFn ( ref f) => self . with_in_scope_lifetime_defs (
1079
- f. generic_params . iter ( ) . filter_map ( |p | match p {
1080
- GenericParamAST :: Lifetime ( ld ) => Some ( ld ) ,
1079
+ f. generic_params . iter ( ) . filter_map ( |param | match param . kind {
1080
+ GenericParamKindAST :: Lifetime { .. } => Some ( param ) ,
1081
1081
_ => None ,
1082
1082
} ) ,
1083
1083
|this| {
@@ -1940,21 +1940,19 @@ impl<'a> LoweringContext<'a> {
1940
1940
add_bounds : & NodeMap < Vec < TyParamBound > > ,
1941
1941
itctx : ImplTraitContext )
1942
1942
-> hir:: GenericParam {
1943
- match param {
1944
- GenericParamAST :: Lifetime ( ref lifetime_def ) => {
1943
+ match param. kind {
1944
+ GenericParamKindAST :: Lifetime { ref bounds , ref lifetime , .. } => {
1945
1945
let was_collecting_in_band = self . is_collecting_in_band_lifetimes ;
1946
1946
self . is_collecting_in_band_lifetimes = false ;
1947
1947
1948
- let lifetime = self . lower_lifetime ( & lifetime_def . lifetime ) ;
1948
+ let lifetime = self . lower_lifetime ( lifetime) ;
1949
1949
let param = hir:: GenericParam {
1950
1950
id : lifetime. id ,
1951
1951
span : lifetime. span ,
1952
- pure_wrt_drop : attr:: contains_name ( & lifetime_def . attrs , "may_dangle" ) ,
1952
+ pure_wrt_drop : attr:: contains_name ( & param . attrs , "may_dangle" ) ,
1953
1953
kind : hir:: GenericParamKind :: Lifetime {
1954
1954
name : lifetime. name ,
1955
- bounds : lifetime_def. bounds
1956
- . iter ( )
1957
- . map ( |lt| self . lower_lifetime ( lt) ) . collect ( ) ,
1955
+ bounds : bounds. iter ( ) . map ( |lt| self . lower_lifetime ( lt) ) . collect ( ) ,
1958
1956
in_band : false ,
1959
1957
lifetime_deprecated : lifetime,
1960
1958
}
@@ -1964,8 +1962,8 @@ impl<'a> LoweringContext<'a> {
1964
1962
1965
1963
param
1966
1964
}
1967
- GenericParamAST :: Type ( ref ty_param ) => {
1968
- let mut name = self . lower_ident ( ty_param . ident ) ;
1965
+ GenericParamKindAST :: Type { ref bounds , ref default } => {
1966
+ let mut name = self . lower_ident ( param . ident ) ;
1969
1967
1970
1968
// Don't expose `Self` (recovered "keyword used as ident" parse error).
1971
1969
// `rustc::ty` expects `Self` to be only used for a trait's `Self`.
@@ -1974,8 +1972,8 @@ impl<'a> LoweringContext<'a> {
1974
1972
name = Symbol :: gensym ( "Self" ) ;
1975
1973
}
1976
1974
1977
- let mut bounds = self . lower_bounds ( & ty_param . bounds , itctx) ;
1978
- let add_bounds = add_bounds. get ( & ty_param . id ) . map_or ( & [ ] [ ..] , |x| & x) ;
1975
+ let mut bounds = self . lower_bounds ( bounds, itctx) ;
1976
+ let add_bounds = add_bounds. get ( & param . id ) . map_or ( & [ ] [ ..] , |x| & x) ;
1979
1977
if !add_bounds. is_empty ( ) {
1980
1978
bounds = bounds
1981
1979
. into_iter ( )
@@ -1984,22 +1982,20 @@ impl<'a> LoweringContext<'a> {
1984
1982
}
1985
1983
1986
1984
hir:: GenericParam {
1987
- id : self . lower_node_id ( ty_param . id ) . node_id ,
1988
- span : ty_param . ident . span ,
1989
- pure_wrt_drop : attr:: contains_name ( & ty_param . attrs , "may_dangle" ) ,
1985
+ id : self . lower_node_id ( param . id ) . node_id ,
1986
+ span : param . ident . span ,
1987
+ pure_wrt_drop : attr:: contains_name ( & param . attrs , "may_dangle" ) ,
1990
1988
kind : hir:: GenericParamKind :: Type {
1991
1989
name,
1992
1990
bounds,
1993
- default : ty_param. default . as_ref ( )
1994
- . map ( |x| {
1995
- self . lower_ty ( x, ImplTraitContext :: Disallowed )
1996
- } ) ,
1997
- synthetic : ty_param. attrs
1998
- . iter ( )
1999
- . filter ( |attr| attr. check_name ( "rustc_synthetic" ) )
2000
- . map ( |_| hir:: SyntheticTyParamKind :: ImplTrait )
2001
- . nth ( 0 ) ,
2002
- attrs : self . lower_attrs ( & ty_param. attrs ) ,
1991
+ default : default. as_ref ( ) . map ( |x| {
1992
+ self . lower_ty ( x, ImplTraitContext :: Disallowed )
1993
+ } ) ,
1994
+ synthetic : param. attrs . iter ( )
1995
+ . filter ( |attr| attr. check_name ( "rustc_synthetic" ) )
1996
+ . map ( |_| hir:: SyntheticTyParamKind :: ImplTrait )
1997
+ . nth ( 0 ) ,
1998
+ attrs : self . lower_attrs ( & param. attrs ) ,
2003
1999
}
2004
2000
}
2005
2001
}
@@ -2015,13 +2011,18 @@ impl<'a> LoweringContext<'a> {
2015
2011
params. iter ( ) . map ( |param| self . lower_generic_param ( param, add_bounds, itctx) ) . collect ( )
2016
2012
}
2017
2013
2018
- fn lower_generics ( & mut self , g : & Generics , itctx : ImplTraitContext ) -> hir:: Generics {
2014
+ fn lower_generics (
2015
+ & mut self ,
2016
+ generics : & Generics ,
2017
+ itctx : ImplTraitContext )
2018
+ -> hir:: Generics
2019
+ {
2019
2020
// Collect `?Trait` bounds in where clause and move them to parameter definitions.
2020
2021
// FIXME: This could probably be done with less rightward drift. Also looks like two control
2021
2022
// paths where report_error is called are also the only paths that advance to after
2022
2023
// the match statement, so the error reporting could probably just be moved there.
2023
2024
let mut add_bounds = NodeMap ( ) ;
2024
- for pred in & g . where_clause . predicates {
2025
+ for pred in & generics . where_clause . predicates {
2025
2026
if let WherePredicate :: BoundPredicate ( ref bound_pred) = * pred {
2026
2027
' next_bound: for bound in & bound_pred. bounds {
2027
2028
if let TraitTyParamBound ( _, TraitBoundModifier :: Maybe ) = * bound {
@@ -2045,15 +2046,17 @@ impl<'a> LoweringContext<'a> {
2045
2046
if let Some ( node_id) =
2046
2047
self . resolver . definitions ( ) . as_local_node_id ( def_id)
2047
2048
{
2048
- for param in & g. params {
2049
- if let GenericParamAST :: Type ( ref ty_param) = * param {
2050
- if node_id == ty_param. id {
2051
- add_bounds
2052
- . entry ( ty_param. id )
2053
- . or_insert ( Vec :: new ( ) )
2054
- . push ( bound. clone ( ) ) ;
2055
- continue ' next_bound;
2049
+ for param in & generics. params {
2050
+ match param. kind {
2051
+ GenericParamKindAST :: Type { .. } => {
2052
+ if node_id == param. id {
2053
+ add_bounds. entry ( param. id )
2054
+ . or_insert ( Vec :: new ( ) )
2055
+ . push ( bound. clone ( ) ) ;
2056
+ continue ' next_bound;
2057
+ }
2056
2058
}
2059
+ _ => { }
2057
2060
}
2058
2061
}
2059
2062
}
@@ -2068,9 +2071,9 @@ impl<'a> LoweringContext<'a> {
2068
2071
}
2069
2072
2070
2073
hir:: Generics {
2071
- params : self . lower_generic_params ( & g . params , & add_bounds, itctx) ,
2072
- where_clause : self . lower_where_clause ( & g . where_clause ) ,
2073
- span : g . span ,
2074
+ params : self . lower_generic_params ( & generics . params , & add_bounds, itctx) ,
2075
+ where_clause : self . lower_where_clause ( & generics . where_clause ) ,
2076
+ span : generics . span ,
2074
2077
}
2075
2078
}
2076
2079
@@ -2093,8 +2096,8 @@ impl<'a> LoweringContext<'a> {
2093
2096
span,
2094
2097
} ) => {
2095
2098
self . with_in_scope_lifetime_defs (
2096
- bound_generic_params. iter ( ) . filter_map ( |p | match p {
2097
- GenericParamAST :: Lifetime ( ld ) => Some ( ld ) ,
2099
+ bound_generic_params. iter ( ) . filter_map ( |param | match param . kind {
2100
+ GenericParamKindAST :: Lifetime { .. } => Some ( param ) ,
2098
2101
_ => None ,
2099
2102
} ) ,
2100
2103
|this| {
@@ -2412,8 +2415,8 @@ impl<'a> LoweringContext<'a> {
2412
2415
) ;
2413
2416
2414
2417
let new_impl_items = self . with_in_scope_lifetime_defs (
2415
- ast_generics. params . iter ( ) . filter_map ( |p | match p {
2416
- GenericParamAST :: Lifetime ( ld ) => Some ( ld ) ,
2418
+ ast_generics. params . iter ( ) . filter_map ( |param | match param . kind {
2419
+ GenericParamKindAST :: Lifetime { .. } => Some ( param ) ,
2417
2420
_ => None ,
2418
2421
} ) ,
2419
2422
|this| {
0 commit comments