@@ -1318,7 +1318,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13181318 span : t. span ,
13191319 } ,
13201320 itctx,
1321- ast:: Const :: No ,
1321+ ast:: BoundConstness :: Never ,
13221322 ) ;
13231323 let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
13241324 let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1426,18 +1426,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14261426 GenericBound :: Trait (
14271427 ty,
14281428 modifier @ ( TraitBoundModifier :: None
1429+ | TraitBoundModifier :: Const ( _)
14291430 | TraitBoundModifier :: MaybeConst ( _)
14301431 | TraitBoundModifier :: Negative ) ,
14311432 ) => {
14321433 Some ( this. lower_poly_trait_ref ( ty, itctx, modifier. to_constness ( ) ) )
14331434 }
1434- // `~ const ?Bound` will cause an error during AST validation
1435+ // `{,~} const ?Bound` will cause an error during AST validation
14351436 // anyways, so treat it like `?Bound` as compilation proceeds.
14361437 GenericBound :: Trait (
14371438 _,
14381439 TraitBoundModifier :: Maybe
14391440 | TraitBoundModifier :: MaybeConstMaybe
1440- | TraitBoundModifier :: MaybeConstNegative ,
1441+ | TraitBoundModifier :: MaybeConstNegative
1442+ | TraitBoundModifier :: ConstMaybe
1443+ | TraitBoundModifier :: ConstNegative ,
14411444 ) => None ,
14421445 GenericBound :: Outlives ( lifetime) => {
14431446 if lifetime_bound. is_none ( ) {
@@ -2176,7 +2179,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21762179
21772180 fn lower_trait_ref (
21782181 & mut self ,
2179- constness : ast:: Const ,
2182+ constness : ast:: BoundConstness ,
21802183 p : & TraitRef ,
21812184 itctx : & ImplTraitContext ,
21822185 ) -> hir:: TraitRef < ' hir > {
@@ -2199,7 +2202,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21992202 & mut self ,
22002203 p : & PolyTraitRef ,
22012204 itctx : & ImplTraitContext ,
2202- constness : ast:: Const ,
2205+ constness : ast:: BoundConstness ,
22032206 ) -> hir:: PolyTraitRef < ' hir > {
22042207 let bound_generic_params =
22052208 self . lower_lifetime_binder ( p. trait_ref . ref_id , & p. bound_generic_params ) ;
@@ -2323,6 +2326,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23232326 fn lower_trait_bound_modifier ( & mut self , f : TraitBoundModifier ) -> hir:: TraitBoundModifier {
23242327 match f {
23252328 TraitBoundModifier :: None => hir:: TraitBoundModifier :: None ,
2329+ TraitBoundModifier :: Const ( _) => hir:: TraitBoundModifier :: Const ,
23262330 TraitBoundModifier :: MaybeConst ( _) => hir:: TraitBoundModifier :: MaybeConst ,
23272331
23282332 TraitBoundModifier :: Negative => {
@@ -2333,12 +2337,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23332337 }
23342338 }
23352339
2336- // `MaybeConstMaybe ` will cause an error during AST validation, but we need to pick a
2340+ // `{,Maybe}ConstMaybe ` will cause an error during AST validation, but we need to pick a
23372341 // placeholder for compilation to proceed.
2338- TraitBoundModifier :: MaybeConstMaybe | TraitBoundModifier :: Maybe => {
2339- hir :: TraitBoundModifier :: Maybe
2340- }
2342+ TraitBoundModifier :: ConstMaybe
2343+ | TraitBoundModifier :: MaybeConstMaybe
2344+ | TraitBoundModifier :: Maybe => hir :: TraitBoundModifier :: Maybe ,
23412345 TraitBoundModifier :: MaybeConstNegative => hir:: TraitBoundModifier :: MaybeConst ,
2346+ TraitBoundModifier :: ConstNegative => hir:: TraitBoundModifier :: Const ,
23422347 }
23432348 }
23442349
@@ -2556,45 +2561,62 @@ struct GenericArgsCtor<'hir> {
25562561}
25572562
25582563impl < ' hir > GenericArgsCtor < ' hir > {
2559- fn push_constness ( & mut self , lcx : & mut LoweringContext < ' _ , ' hir > , constness : ast:: Const ) {
2564+ fn push_constness (
2565+ & mut self ,
2566+ lcx : & mut LoweringContext < ' _ , ' hir > ,
2567+ constness : ast:: BoundConstness ,
2568+ ) {
25602569 if !lcx. tcx . features ( ) . effects {
25612570 return ;
25622571 }
25632572
2564- // if bound is non-const, don't add host effect param
2565- let ast:: Const :: Yes ( span) = constness else { return } ;
2573+ let ( span, body) = match constness {
2574+ BoundConstness :: Never => return ,
2575+ BoundConstness :: Always ( span) => {
2576+ let span = lcx. lower_span ( span) ;
25662577
2567- let span = lcx. lower_span ( span) ;
2578+ let body = hir:: ExprKind :: Lit (
2579+ lcx. arena . alloc ( hir:: Lit { node : LitKind :: Bool ( false ) , span } ) ,
2580+ ) ;
25682581
2569- let id = lcx. next_node_id ( ) ;
2570- let hir_id = lcx. next_id ( ) ;
2582+ ( span, body)
2583+ }
2584+ BoundConstness :: Maybe ( span) => {
2585+ let span = lcx. lower_span ( span) ;
25712586
2572- let Some ( host_param_id) = lcx. host_param_id else {
2573- lcx. tcx . sess . span_delayed_bug (
2574- span,
2575- "no host param id for call in const yet no errors reported" ,
2576- ) ;
2577- return ;
2578- } ;
2587+ let Some ( host_param_id) = lcx. host_param_id else {
2588+ lcx. tcx . sess . span_delayed_bug (
2589+ span,
2590+ "no host param id for call in const yet no errors reported" ,
2591+ ) ;
2592+ return ;
2593+ } ;
25792594
2580- let body = lcx. lower_body ( |lcx| {
2581- ( & [ ] , {
25822595 let hir_id = lcx. next_id ( ) ;
25832596 let res = Res :: Def ( DefKind :: ConstParam , host_param_id. to_def_id ( ) ) ;
2584- let expr_kind = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
2597+ let body = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
25852598 None ,
25862599 lcx. arena . alloc ( hir:: Path {
25872600 span,
25882601 res,
2589- segments : arena_vec ! [ lcx; hir:: PathSegment :: new( Ident {
2590- name: sym:: host,
2591- span,
2592- } , hir_id, res) ] ,
2602+ segments : arena_vec ! [
2603+ lcx;
2604+ hir:: PathSegment :: new(
2605+ Ident { name: sym:: host, span } ,
2606+ hir_id,
2607+ res
2608+ )
2609+ ] ,
25932610 } ) ,
25942611 ) ) ;
2595- lcx. expr ( span, expr_kind)
2596- } )
2597- } ) ;
2612+
2613+ ( span, body)
2614+ }
2615+ } ;
2616+ let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2617+
2618+ let id = lcx. next_node_id ( ) ;
2619+ let hir_id = lcx. next_id ( ) ;
25982620
25992621 let def_id = lcx. create_def (
26002622 lcx. current_hir_id_owner . def_id ,
0 commit comments