@@ -1221,41 +1221,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1221
1221
)
1222
1222
}
1223
1223
ImplTraitContext :: Universal => {
1224
- // Add a definition for the in-band `Param`.
1225
- let def_id = self . resolver . local_def_id ( def_node_id) ;
1226
-
1227
- let hir_bounds =
1228
- self . lower_param_bounds ( bounds, ImplTraitContext :: Universal ) ;
1229
- // Set the name to `impl Bound1 + Bound2`.
1224
+ let span = t. span ;
1230
1225
let ident = Ident :: from_str_and_span ( & pprust:: ty_to_string ( t) , span) ;
1231
- let param = hir:: GenericParam {
1232
- hir_id : self . lower_node_id ( def_node_id) ,
1233
- name : ParamName :: Plain ( self . lower_ident ( ident) ) ,
1234
- pure_wrt_drop : false ,
1235
- span : self . lower_span ( span) ,
1236
- kind : hir:: GenericParamKind :: Type { default : None , synthetic : true } ,
1237
- colon_span : None ,
1238
- } ;
1226
+ let ( param, bounds, path) =
1227
+ self . lower_generic_and_bounds ( def_node_id, span, ident, bounds) ;
1239
1228
self . impl_trait_defs . push ( param) ;
1240
-
1241
- if let Some ( preds) = self . lower_generic_bound_predicate (
1242
- ident,
1243
- def_node_id,
1244
- & GenericParamKind :: Type { default : None } ,
1245
- hir_bounds,
1246
- hir:: PredicateOrigin :: ImplTrait ,
1247
- ) {
1248
- self . impl_trait_bounds . push ( preds)
1229
+ if let Some ( bounds) = bounds {
1230
+ self . impl_trait_bounds . push ( bounds) ;
1249
1231
}
1250
-
1251
- hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1252
- None ,
1253
- self . arena . alloc ( hir:: Path {
1254
- span : self . lower_span ( span) ,
1255
- res : Res :: Def ( DefKind :: TyParam , def_id. to_def_id ( ) ) ,
1256
- segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident( self . lower_ident( ident) ) ] ,
1257
- } ) ,
1258
- ) )
1232
+ path
1259
1233
}
1260
1234
ImplTraitContext :: Disallowed ( position) => {
1261
1235
let mut err = struct_span_err ! (
@@ -1972,6 +1946,47 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1972
1946
bounds. iter ( ) . map ( move |bound| self . lower_param_bound ( bound, itctx) )
1973
1947
}
1974
1948
1949
+ fn lower_generic_and_bounds (
1950
+ & mut self ,
1951
+ node_id : NodeId ,
1952
+ span : Span ,
1953
+ ident : Ident ,
1954
+ bounds : & [ GenericBound ] ,
1955
+ ) -> ( hir:: GenericParam < ' hir > , Option < hir:: WherePredicate < ' hir > > , hir:: TyKind < ' hir > ) {
1956
+ // Add a definition for the in-band `Param`.
1957
+ let def_id = self . resolver . local_def_id ( node_id) ;
1958
+
1959
+ let hir_bounds = self . lower_param_bounds ( bounds, ImplTraitContext :: Universal ) ;
1960
+ // Set the name to `impl Bound1 + Bound2`.
1961
+ let param = hir:: GenericParam {
1962
+ hir_id : self . lower_node_id ( node_id) ,
1963
+ name : ParamName :: Plain ( self . lower_ident ( ident) ) ,
1964
+ pure_wrt_drop : false ,
1965
+ span : self . lower_span ( span) ,
1966
+ kind : hir:: GenericParamKind :: Type { default : None , synthetic : true } ,
1967
+ colon_span : None ,
1968
+ } ;
1969
+
1970
+ let preds = self . lower_generic_bound_predicate (
1971
+ ident,
1972
+ node_id,
1973
+ & GenericParamKind :: Type { default : None } ,
1974
+ hir_bounds,
1975
+ hir:: PredicateOrigin :: ImplTrait ,
1976
+ ) ;
1977
+
1978
+ let ty = hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1979
+ None ,
1980
+ self . arena . alloc ( hir:: Path {
1981
+ span : self . lower_span ( span) ,
1982
+ res : Res :: Def ( DefKind :: TyParam , def_id. to_def_id ( ) ) ,
1983
+ segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident( self . lower_ident( ident) ) ] ,
1984
+ } ) ,
1985
+ ) ) ;
1986
+
1987
+ ( param, preds, ty)
1988
+ }
1989
+
1975
1990
/// Lowers a block directly to an expression, presuming that it
1976
1991
/// has no attributes and is not targeted by a `break`.
1977
1992
fn lower_block_expr ( & mut self , b : & Block ) -> hir:: Expr < ' hir > {
0 commit comments