@@ -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 < LocalDefId > ,
145147}
146148
147149trait ResolverAstLoweringExt {
@@ -1267,6 +1269,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12671269 span : t. span
12681270 } ,
12691271 itctx,
1272+ ast:: Const :: No ,
12701273 ) ;
12711274 let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
12721275 let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1277,7 +1280,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12771280 }
12781281
12791282 let id = self . lower_node_id ( t. id ) ;
1280- let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx) ;
1283+ let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx, None ) ;
12811284 self . ty_path ( id, t. span , qpath)
12821285 }
12831286
@@ -1361,10 +1364,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13611364 this. arena . alloc_from_iter ( bounds. iter ( ) . filter_map ( |bound| match bound {
13621365 GenericBound :: Trait (
13631366 ty,
1364- TraitBoundModifier :: None
1367+ modifier @ ( TraitBoundModifier :: None
13651368 | TraitBoundModifier :: MaybeConst
1366- | TraitBoundModifier :: Negative ,
1367- ) => Some ( this. lower_poly_trait_ref ( ty, itctx) ) ,
1369+ | TraitBoundModifier :: Negative ) ,
1370+ ) => {
1371+ Some ( this. lower_poly_trait_ref ( ty, itctx, modifier. to_constness ( ) ) )
1372+ }
13681373 // `~const ?Bound` will cause an error during AST validation
13691374 // anyways, so treat it like `?Bound` as compilation proceeds.
13701375 GenericBound :: Trait (
@@ -2189,7 +2194,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21892194 ) -> hir:: GenericBound < ' hir > {
21902195 match tpb {
21912196 GenericBound :: Trait ( p, modifier) => hir:: GenericBound :: Trait (
2192- self . lower_poly_trait_ref ( p, itctx) ,
2197+ self . lower_poly_trait_ref ( p, itctx, modifier . to_constness ( ) ) ,
21932198 self . lower_trait_bound_modifier ( * modifier) ,
21942199 ) ,
21952200 GenericBound :: Outlives ( lifetime) => {
@@ -2332,8 +2337,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23322337 }
23332338 }
23342339
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) {
2340+ fn lower_trait_ref (
2341+ & mut self ,
2342+ constness : ast:: Const ,
2343+ p : & TraitRef ,
2344+ itctx : & ImplTraitContext ,
2345+ ) -> hir:: TraitRef < ' hir > {
2346+ let path = match self . lower_qpath (
2347+ p. ref_id ,
2348+ & None ,
2349+ & p. path ,
2350+ ParamMode :: Explicit ,
2351+ itctx,
2352+ Some ( constness) ,
2353+ ) {
23372354 hir:: QPath :: Resolved ( None , path) => path,
23382355 qpath => panic ! ( "lower_trait_ref: unexpected QPath `{qpath:?}`" ) ,
23392356 } ;
@@ -2345,10 +2362,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23452362 & mut self ,
23462363 p : & PolyTraitRef ,
23472364 itctx : & ImplTraitContext ,
2365+ constness : ast:: Const ,
23482366 ) -> hir:: PolyTraitRef < ' hir > {
23492367 let bound_generic_params =
23502368 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) ;
2369+ let trait_ref = self . lower_trait_ref ( constness , & p. trait_ref , itctx) ;
23522370 hir:: PolyTraitRef { bound_generic_params, trait_ref, span : self . lower_span ( p. span ) }
23532371 }
23542372
@@ -2702,6 +2720,57 @@ struct GenericArgsCtor<'hir> {
27022720}
27032721
27042722impl < ' hir > GenericArgsCtor < ' hir > {
2723+ fn push_constness ( & mut self , lcx : & mut LoweringContext < ' _ , ' hir > , constness : ast:: Const ) {
2724+ if !lcx. tcx . features ( ) . effects {
2725+ return ;
2726+ }
2727+
2728+ // if bound is non-const, don't add host effect param
2729+ let ast:: Const :: Yes ( span) = constness else { return } ;
2730+
2731+ let span = lcx. lower_span ( span) ;
2732+
2733+ let id = lcx. next_node_id ( ) ;
2734+ let hir_id = lcx. next_id ( ) ;
2735+ let body = lcx. lower_body ( |lcx| {
2736+ (
2737+ & [ ] ,
2738+ match constness {
2739+ ast:: Const :: Yes ( _) => {
2740+ let hir_id = lcx. next_id ( ) ;
2741+ let res =
2742+ Res :: Def ( DefKind :: ConstParam , lcx. host_param_id . unwrap ( ) . to_def_id ( ) ) ;
2743+ let expr_kind = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
2744+ None ,
2745+ lcx. arena . alloc ( hir:: Path {
2746+ span,
2747+ res,
2748+ segments : arena_vec ! [ lcx; hir:: PathSegment :: new( Ident {
2749+ name: sym:: host,
2750+ span,
2751+ } , hir_id, res) ] ,
2752+ } ) ,
2753+ ) ) ;
2754+ lcx. expr ( span, expr_kind)
2755+ }
2756+ ast:: Const :: No => lcx. expr (
2757+ span,
2758+ hir:: ExprKind :: Lit (
2759+ lcx. arena . alloc ( hir:: Lit { span, node : ast:: LitKind :: Bool ( true ) } ) ,
2760+ ) ,
2761+ ) ,
2762+ } ,
2763+ )
2764+ } ) ;
2765+ let def_id =
2766+ lcx. create_def ( lcx. current_hir_id_owner . def_id , id, DefPathData :: AnonConst , span) ;
2767+ lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
2768+ self . args . push ( hir:: GenericArg :: Const ( hir:: ConstArg {
2769+ value : hir:: AnonConst { def_id, hir_id, body } ,
2770+ span,
2771+ } ) )
2772+ }
2773+
27052774 fn is_empty ( & self ) -> bool {
27062775 self . args . is_empty ( )
27072776 && self . bindings . is_empty ( )
0 commit comments