@@ -1318,7 +1318,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1318
1318
span : t. span ,
1319
1319
} ,
1320
1320
itctx,
1321
- ast:: Const :: No ,
1321
+ ast:: BoundConstness :: Never ,
1322
1322
) ;
1323
1323
let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
1324
1324
let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1426,18 +1426,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1426
1426
GenericBound :: Trait (
1427
1427
ty,
1428
1428
modifier @ ( TraitBoundModifier :: None
1429
+ | TraitBoundModifier :: Const ( _)
1429
1430
| TraitBoundModifier :: MaybeConst ( _)
1430
1431
| TraitBoundModifier :: Negative ) ,
1431
1432
) => {
1432
1433
Some ( this. lower_poly_trait_ref ( ty, itctx, modifier. to_constness ( ) ) )
1433
1434
}
1434
- // `~ const ?Bound` will cause an error during AST validation
1435
+ // `{,~} const ?Bound` will cause an error during AST validation
1435
1436
// anyways, so treat it like `?Bound` as compilation proceeds.
1436
1437
GenericBound :: Trait (
1437
1438
_,
1438
1439
TraitBoundModifier :: Maybe
1439
1440
| TraitBoundModifier :: MaybeConstMaybe
1440
- | TraitBoundModifier :: MaybeConstNegative ,
1441
+ | TraitBoundModifier :: MaybeConstNegative
1442
+ | TraitBoundModifier :: ConstMaybe
1443
+ | TraitBoundModifier :: ConstNegative ,
1441
1444
) => None ,
1442
1445
GenericBound :: Outlives ( lifetime) => {
1443
1446
if lifetime_bound. is_none ( ) {
@@ -2176,7 +2179,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2176
2179
2177
2180
fn lower_trait_ref (
2178
2181
& mut self ,
2179
- constness : ast:: Const ,
2182
+ constness : ast:: BoundConstness ,
2180
2183
p : & TraitRef ,
2181
2184
itctx : & ImplTraitContext ,
2182
2185
) -> hir:: TraitRef < ' hir > {
@@ -2199,7 +2202,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2199
2202
& mut self ,
2200
2203
p : & PolyTraitRef ,
2201
2204
itctx : & ImplTraitContext ,
2202
- constness : ast:: Const ,
2205
+ constness : ast:: BoundConstness ,
2203
2206
) -> hir:: PolyTraitRef < ' hir > {
2204
2207
let bound_generic_params =
2205
2208
self . lower_lifetime_binder ( p. trait_ref . ref_id , & p. bound_generic_params ) ;
@@ -2323,6 +2326,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2323
2326
fn lower_trait_bound_modifier ( & mut self , f : TraitBoundModifier ) -> hir:: TraitBoundModifier {
2324
2327
match f {
2325
2328
TraitBoundModifier :: None => hir:: TraitBoundModifier :: None ,
2329
+ TraitBoundModifier :: Const ( _) => hir:: TraitBoundModifier :: Const ,
2326
2330
TraitBoundModifier :: MaybeConst ( _) => hir:: TraitBoundModifier :: MaybeConst ,
2327
2331
2328
2332
TraitBoundModifier :: Negative => {
@@ -2333,12 +2337,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2333
2337
}
2334
2338
}
2335
2339
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
2337
2341
// 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 ,
2341
2345
TraitBoundModifier :: MaybeConstNegative => hir:: TraitBoundModifier :: MaybeConst ,
2346
+ TraitBoundModifier :: ConstNegative => hir:: TraitBoundModifier :: Const ,
2342
2347
}
2343
2348
}
2344
2349
@@ -2556,45 +2561,62 @@ struct GenericArgsCtor<'hir> {
2556
2561
}
2557
2562
2558
2563
impl < ' 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
+ ) {
2560
2569
if !lcx. tcx . features ( ) . effects {
2561
2570
return ;
2562
2571
}
2563
2572
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) ;
2566
2577
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
+ ) ;
2568
2581
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) ;
2571
2586
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
+ } ;
2579
2594
2580
- let body = lcx. lower_body ( |lcx| {
2581
- ( & [ ] , {
2582
2595
let hir_id = lcx. next_id ( ) ;
2583
2596
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 (
2585
2598
None ,
2586
2599
lcx. arena . alloc ( hir:: Path {
2587
2600
span,
2588
2601
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
+ ] ,
2593
2610
} ) ,
2594
2611
) ) ;
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 ( ) ;
2598
2620
2599
2621
let def_id = lcx. create_def (
2600
2622
lcx. current_hir_id_owner . def_id ,
0 commit comments