@@ -1324,7 +1324,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13241324 span : t. span ,
13251325 } ,
13261326 itctx,
1327- ast:: Const :: No ,
1327+ ast:: BoundConstness :: Never ,
13281328 ) ;
13291329 let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
13301330 let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1435,7 +1435,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14351435 polarity : BoundPolarity :: Positive | BoundPolarity :: Negative ( _) ,
14361436 constness,
14371437 } ,
1438- ) => Some ( this. lower_poly_trait_ref ( ty, itctx, ( * constness) . into ( ) ) ) ,
1438+ ) => Some ( this. lower_poly_trait_ref ( ty, itctx, * constness) ) ,
14391439 // We can safely ignore constness here, since AST validation
14401440 // will take care of invalid modifier combinations.
14411441 GenericBound :: Trait (
@@ -2174,7 +2174,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21742174
21752175 fn lower_trait_ref (
21762176 & mut self ,
2177- constness : ast:: Const ,
2177+ constness : ast:: BoundConstness ,
21782178 p : & TraitRef ,
21792179 itctx : & ImplTraitContext ,
21802180 ) -> hir:: TraitRef < ' hir > {
@@ -2197,7 +2197,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21972197 & mut self ,
21982198 p : & PolyTraitRef ,
21992199 itctx : & ImplTraitContext ,
2200- constness : ast:: Const ,
2200+ constness : ast:: BoundConstness ,
22012201 ) -> hir:: PolyTraitRef < ' hir > {
22022202 let bound_generic_params =
22032203 self . lower_lifetime_binder ( p. trait_ref . ref_id , & p. bound_generic_params ) ;
@@ -2322,25 +2322,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23222322 & mut self ,
23232323 modifiers : TraitBoundModifiers ,
23242324 ) -> hir:: TraitBoundModifier {
2325+ // Invalid modifier combinations will cause an error during AST validation.
2326+ // Arbitrarily pick a placeholder for them to make compilation proceed.
23252327 match ( modifiers. constness , modifiers. polarity ) {
23262328 ( BoundConstness :: Never , BoundPolarity :: Positive ) => hir:: TraitBoundModifier :: None ,
2327- ( BoundConstness :: Never , BoundPolarity :: Maybe ( _) ) => hir:: TraitBoundModifier :: Maybe ,
2329+ ( _ , BoundPolarity :: Maybe ( _) ) => hir:: TraitBoundModifier :: Maybe ,
23282330 ( BoundConstness :: Never , BoundPolarity :: Negative ( _) ) => {
23292331 if self . tcx . features ( ) . negative_bounds {
23302332 hir:: TraitBoundModifier :: Negative
23312333 } else {
23322334 hir:: TraitBoundModifier :: None
23332335 }
23342336 }
2335- ( BoundConstness :: Maybe ( _) , BoundPolarity :: Positive ) => {
2336- hir:: TraitBoundModifier :: MaybeConst
2337- }
2338- // Invalid modifier combinations will cause an error during AST validation.
2339- // Arbitrarily pick a placeholder for compilation to proceed.
2340- ( BoundConstness :: Maybe ( _) , BoundPolarity :: Maybe ( _) ) => hir:: TraitBoundModifier :: Maybe ,
2341- ( BoundConstness :: Maybe ( _) , BoundPolarity :: Negative ( _) ) => {
2342- hir:: TraitBoundModifier :: MaybeConst
2343- }
2337+ ( BoundConstness :: Always ( _) , _) => hir:: TraitBoundModifier :: Const ,
2338+ ( BoundConstness :: Maybe ( _) , _) => hir:: TraitBoundModifier :: MaybeConst ,
23442339 }
23452340 }
23462341
@@ -2558,45 +2553,62 @@ struct GenericArgsCtor<'hir> {
25582553}
25592554
25602555impl < ' hir > GenericArgsCtor < ' hir > {
2561- fn push_constness ( & mut self , lcx : & mut LoweringContext < ' _ , ' hir > , constness : ast:: Const ) {
2556+ fn push_constness (
2557+ & mut self ,
2558+ lcx : & mut LoweringContext < ' _ , ' hir > ,
2559+ constness : ast:: BoundConstness ,
2560+ ) {
25622561 if !lcx. tcx . features ( ) . effects {
25632562 return ;
25642563 }
25652564
2566- // if bound is non-const, don't add host effect param
2567- let ast:: Const :: Yes ( span) = constness else { return } ;
2565+ let ( span, body) = match constness {
2566+ BoundConstness :: Never => return ,
2567+ BoundConstness :: Always ( span) => {
2568+ let span = lcx. lower_span ( span) ;
25682569
2569- let span = lcx. lower_span ( span) ;
2570+ let body = hir:: ExprKind :: Lit (
2571+ lcx. arena . alloc ( hir:: Lit { node : LitKind :: Bool ( false ) , span } ) ,
2572+ ) ;
25702573
2571- let id = lcx. next_node_id ( ) ;
2572- let hir_id = lcx. next_id ( ) ;
2574+ ( span, body)
2575+ }
2576+ BoundConstness :: Maybe ( span) => {
2577+ let span = lcx. lower_span ( span) ;
25732578
2574- let Some ( host_param_id) = lcx. host_param_id else {
2575- lcx. dcx ( ) . span_delayed_bug (
2576- span,
2577- "no host param id for call in const yet no errors reported" ,
2578- ) ;
2579- return ;
2580- } ;
2579+ let Some ( host_param_id) = lcx. host_param_id else {
2580+ lcx. dcx ( ) . span_delayed_bug (
2581+ span,
2582+ "no host param id for call in const yet no errors reported" ,
2583+ ) ;
2584+ return ;
2585+ } ;
25812586
2582- let body = lcx. lower_body ( |lcx| {
2583- ( & [ ] , {
25842587 let hir_id = lcx. next_id ( ) ;
25852588 let res = Res :: Def ( DefKind :: ConstParam , host_param_id. to_def_id ( ) ) ;
2586- let expr_kind = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
2589+ let body = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
25872590 None ,
25882591 lcx. arena . alloc ( hir:: Path {
25892592 span,
25902593 res,
2591- segments : arena_vec ! [ lcx; hir:: PathSegment :: new( Ident {
2592- name: sym:: host,
2593- span,
2594- } , hir_id, res) ] ,
2594+ segments : arena_vec ! [
2595+ lcx;
2596+ hir:: PathSegment :: new(
2597+ Ident { name: sym:: host, span } ,
2598+ hir_id,
2599+ res
2600+ )
2601+ ] ,
25952602 } ) ,
25962603 ) ) ;
2597- lcx. expr ( span, expr_kind)
2598- } )
2599- } ) ;
2604+
2605+ ( span, body)
2606+ }
2607+ } ;
2608+ let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2609+
2610+ let id = lcx. next_node_id ( ) ;
2611+ let hir_id = lcx. next_id ( ) ;
26002612
26012613 let def_id = lcx. create_def (
26022614 lcx. current_hir_id_owner . def_id ,
0 commit comments