@@ -142,6 +142,8 @@ struct LoweringContext<'a, 'hir> {
142142 /// defined on the TAIT, so we have type Foo<'a1> = ... and we establish a mapping in this
143143 /// field from the original parameter 'a to the new parameter 'a1.
144144 generics_def_id_map : Vec < FxHashMap < LocalDefId , LocalDefId > > ,
145+
146+ host_param_id : Option < hir:: HirId > ,
145147}
146148
147149trait ResolverAstLoweringExt {
@@ -1267,6 +1269,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12671269 span : t. span
12681270 } ,
12691271 itctx,
1272+ // TODO?
1273+ ast:: Const :: No ,
12701274 ) ;
12711275 let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
12721276 let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1277,7 +1281,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12771281 }
12781282
12791283 let id = self . lower_node_id ( t. id ) ;
1280- let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx) ;
1284+ let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx, None ) ;
12811285 self . ty_path ( id, t. span , qpath)
12821286 }
12831287
@@ -1361,10 +1365,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13611365 this. arena . alloc_from_iter ( bounds. iter ( ) . filter_map ( |bound| match bound {
13621366 GenericBound :: Trait (
13631367 ty,
1364- TraitBoundModifier :: None
1368+ modifier @ ( TraitBoundModifier :: None
13651369 | TraitBoundModifier :: MaybeConst
1366- | TraitBoundModifier :: Negative ,
1367- ) => Some ( this. lower_poly_trait_ref ( ty, itctx) ) ,
1370+ | TraitBoundModifier :: Negative ) ,
1371+ ) => Some ( this. lower_poly_trait_ref ( ty, itctx, modifier . to_constness ( ) ) ) ,
13681372 // `~const ?Bound` will cause an error during AST validation
13691373 // anyways, so treat it like `?Bound` as compilation proceeds.
13701374 GenericBound :: Trait (
@@ -2189,7 +2193,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21892193 ) -> hir:: GenericBound < ' hir > {
21902194 match tpb {
21912195 GenericBound :: Trait ( p, modifier) => hir:: GenericBound :: Trait (
2192- self . lower_poly_trait_ref ( p, itctx) ,
2196+ self . lower_poly_trait_ref ( p, itctx, modifier . to_constness ( ) ) ,
21932197 self . lower_trait_bound_modifier ( * modifier) ,
21942198 ) ,
21952199 GenericBound :: Outlives ( lifetime) => {
@@ -2332,8 +2336,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23322336 }
23332337 }
23342338
2335- fn lower_trait_ref ( & mut self , p : & TraitRef , itctx : & ImplTraitContext ) -> hir:: TraitRef < ' hir > {
2336- let path = match self . lower_qpath ( p. ref_id , & None , & p. path , ParamMode :: Explicit , itctx) {
2339+ fn lower_trait_ref ( & mut self , constness : ast :: Const , p : & TraitRef , itctx : & ImplTraitContext ) -> hir:: TraitRef < ' hir > {
2340+ let path = match self . lower_qpath ( p. ref_id , & None , & p. path , ParamMode :: Explicit , itctx, Some ( constness ) ) {
23372341 hir:: QPath :: Resolved ( None , path) => path,
23382342 qpath => panic ! ( "lower_trait_ref: unexpected QPath `{qpath:?}`" ) ,
23392343 } ;
@@ -2345,10 +2349,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23452349 & mut self ,
23462350 p : & PolyTraitRef ,
23472351 itctx : & ImplTraitContext ,
2352+ constness : ast:: Const ,
23482353 ) -> hir:: PolyTraitRef < ' hir > {
23492354 let bound_generic_params =
23502355 self . lower_lifetime_binder ( p. trait_ref . ref_id , & p. bound_generic_params ) ;
2351- let trait_ref = self . lower_trait_ref ( & p. trait_ref , itctx) ;
2356+ let trait_ref = self . lower_trait_ref ( constness , & p. trait_ref , itctx, ) ;
23522357 hir:: PolyTraitRef { bound_generic_params, trait_ref, span : self . lower_span ( p. span ) }
23532358 }
23542359
@@ -2702,6 +2707,28 @@ struct GenericArgsCtor<'hir> {
27022707}
27032708
27042709impl < ' hir > GenericArgsCtor < ' hir > {
2710+ fn push_constness ( & mut self , lcx : & mut LoweringContext < ' _ , ' hir > , constness : ast:: Const ) {
2711+ let span = if let ast:: Const :: Yes ( sp) = constness {
2712+ sp
2713+ } else {
2714+ DUMMY_SP
2715+ } ;
2716+ let id = lcx. next_node_id ( ) ;
2717+ lcx. lower_body ( |lcx| {
2718+ ( & [ ] , match constness {
2719+ ast:: Const :: Yes ( _) => lcx. expr_ident_mut ( span, Ident { name : sym:: host, span } , binding) ,
2720+ ast:: Const :: No => lcx. expr ( span, hir:: ExprKind :: Lit ( lcx. arena . alloc ( hir:: Lit { span, node : ast:: LitKind :: Bool ( true ) } ) ) ) ,
2721+ } )
2722+ } ) ;
2723+ let def = lcx. create_def ( lcx. current_hir_id_owner . def_id , id, DefPathData :: AnonConst , span) ;
2724+ self . args . push ( hir:: GenericArg :: Const ( hir:: ConstArg {
2725+ value : hir:: AnonConst {
2726+ def_id,
2727+ } ,
2728+ span,
2729+ } ) )
2730+ }
2731+
27052732 fn is_empty ( & self ) -> bool {
27062733 self . args . is_empty ( )
27072734 && self . bindings . is_empty ( )
0 commit comments