@@ -1324,7 +1324,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1324
1324
span : t. span ,
1325
1325
} ,
1326
1326
itctx,
1327
- ast:: Const :: No ,
1327
+ ast:: BoundConstness :: Never ,
1328
1328
) ;
1329
1329
let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
1330
1330
let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1435,7 +1435,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1435
1435
polarity : BoundPolarity :: Positive | BoundPolarity :: Negative ( _) ,
1436
1436
constness,
1437
1437
} ,
1438
- ) => Some ( this. lower_poly_trait_ref ( ty, itctx, ( * constness) . into ( ) ) ) ,
1438
+ ) => Some ( this. lower_poly_trait_ref ( ty, itctx, * constness) ) ,
1439
1439
// We can safely ignore constness here, since AST validation
1440
1440
// will take care of invalid modifier combinations.
1441
1441
GenericBound :: Trait (
@@ -2174,7 +2174,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2174
2174
2175
2175
fn lower_trait_ref (
2176
2176
& mut self ,
2177
- constness : ast:: Const ,
2177
+ constness : ast:: BoundConstness ,
2178
2178
p : & TraitRef ,
2179
2179
itctx : & ImplTraitContext ,
2180
2180
) -> hir:: TraitRef < ' hir > {
@@ -2197,7 +2197,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2197
2197
& mut self ,
2198
2198
p : & PolyTraitRef ,
2199
2199
itctx : & ImplTraitContext ,
2200
- constness : ast:: Const ,
2200
+ constness : ast:: BoundConstness ,
2201
2201
) -> hir:: PolyTraitRef < ' hir > {
2202
2202
let bound_generic_params =
2203
2203
self . lower_lifetime_binder ( p. trait_ref . ref_id , & p. bound_generic_params ) ;
@@ -2322,25 +2322,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2322
2322
& mut self ,
2323
2323
modifiers : TraitBoundModifiers ,
2324
2324
) -> hir:: TraitBoundModifier {
2325
+ // Invalid modifier combinations will cause an error during AST validation.
2326
+ // Arbitrarily pick a placeholder for them to make compilation proceed.
2325
2327
match ( modifiers. constness , modifiers. polarity ) {
2326
2328
( BoundConstness :: Never , BoundPolarity :: Positive ) => hir:: TraitBoundModifier :: None ,
2327
- ( BoundConstness :: Never , BoundPolarity :: Maybe ( _) ) => hir:: TraitBoundModifier :: Maybe ,
2329
+ ( _ , BoundPolarity :: Maybe ( _) ) => hir:: TraitBoundModifier :: Maybe ,
2328
2330
( BoundConstness :: Never , BoundPolarity :: Negative ( _) ) => {
2329
2331
if self . tcx . features ( ) . negative_bounds {
2330
2332
hir:: TraitBoundModifier :: Negative
2331
2333
} else {
2332
2334
hir:: TraitBoundModifier :: None
2333
2335
}
2334
2336
}
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 ,
2344
2339
}
2345
2340
}
2346
2341
@@ -2558,45 +2553,62 @@ struct GenericArgsCtor<'hir> {
2558
2553
}
2559
2554
2560
2555
impl < ' 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
+ ) {
2562
2561
if !lcx. tcx . features ( ) . effects {
2563
2562
return ;
2564
2563
}
2565
2564
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) ;
2568
2569
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
+ ) ;
2570
2573
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) ;
2573
2578
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
+ } ;
2581
2586
2582
- let body = lcx. lower_body ( |lcx| {
2583
- ( & [ ] , {
2584
2587
let hir_id = lcx. next_id ( ) ;
2585
2588
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 (
2587
2590
None ,
2588
2591
lcx. arena . alloc ( hir:: Path {
2589
2592
span,
2590
2593
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
+ ] ,
2595
2602
} ) ,
2596
2603
) ) ;
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 ( ) ;
2600
2612
2601
2613
let def_id = lcx. create_def (
2602
2614
lcx. current_hir_id_owner . def_id ,
0 commit comments