@@ -1221,41 +1221,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12211221 )
12221222 }
12231223 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 ;
12301225 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) ;
12391228 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) ;
12491231 }
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
12591233 }
12601234 ImplTraitContext :: Disallowed ( position) => {
12611235 let mut err = struct_span_err ! (
@@ -1972,6 +1946,47 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19721946 bounds. iter ( ) . map ( move |bound| self . lower_param_bound ( bound, itctx) )
19731947 }
19741948
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+
19751990 /// Lowers a block directly to an expression, presuming that it
19761991 /// has no attributes and is not targeted by a `break`.
19771992 fn lower_block_expr ( & mut self , b : & Block ) -> hir:: Expr < ' hir > {
0 commit comments