@@ -102,8 +102,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
102
102
103
103
ControlFlow :: CONTINUE
104
104
}
105
- Node :: Block ( _, _)
106
- | Node :: Binop ( _, _, _)
105
+ Node :: Binop ( _, _, _)
107
106
| Node :: UnaryOp ( _, _)
108
107
| Node :: FunctionCall ( _, _) => ControlFlow :: CONTINUE ,
109
108
} ) ;
@@ -288,10 +287,6 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
288
287
self . nodes [ func] . used = true ;
289
288
nodes. iter ( ) . for_each ( |& n| self . nodes [ n] . used = true ) ;
290
289
}
291
- Node :: Block ( stmts, opt_expr) => {
292
- stmts. iter ( ) . for_each ( |& id| self . nodes [ id] . used = true ) ;
293
- opt_expr. map ( |e| self . nodes [ e] . used = true ) ;
294
- }
295
290
Node :: Cast ( operand, _) => {
296
291
self . nodes [ operand] . used = true ;
297
292
}
@@ -378,22 +373,14 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
378
373
let arg = self . recurse_build ( arg) ?;
379
374
self . add_node ( Node :: UnaryOp ( op, arg) , node. span )
380
375
} ,
381
- ExprKind :: Block { body } => {
382
- let mut stmts = Vec :: with_capacity ( body. stmts . len ( ) ) ;
383
- for & id in body. stmts . iter ( ) {
384
- match & self . body . stmts [ id] . kind {
385
- thir:: StmtKind :: Let { .. } => return self . error (
386
- Some ( node. span ) ,
387
- "let statements are not supported in generic constants" ,
388
- ) . map ( |never| never) ,
389
- thir:: StmtKind :: Expr { expr, .. } => stmts. push ( self . recurse_build ( * expr) ?) ,
390
- }
391
- } ;
392
- let stmts = self . tcx . arena . alloc_slice ( & stmts) ;
393
- let opt_expr = body. expr . map ( |e| self . recurse_build ( e) ) . transpose ( ) ?;
394
- self . add_node ( Node :: Block ( stmts, opt_expr) , node. span )
395
- }
396
-
376
+ // this is necessary so that the following compiles:
377
+ //
378
+ // ```
379
+ // fn foo<const N: usize>(a: [(); N + 1]) {
380
+ // bar::<{ N + 1 }>();
381
+ // }
382
+ // ```
383
+ ExprKind :: Block { body : thir:: Block { stmts : box [ ] , expr : Some ( e) , .. } } => self . recurse_build ( * e) ?,
397
384
// ExprKind::Use happens when a `hir::ExprKind::Cast` is a
398
385
// "coercion cast" i.e. using a coercion or is a no-op.
399
386
// this is important so that `N as usize as usize` doesnt unify with `N as usize`
@@ -411,6 +398,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
411
398
| ExprKind :: Deref { .. }
412
399
| ExprKind :: Repeat { .. }
413
400
| ExprKind :: Array { .. }
401
+ | ExprKind :: Block { .. }
414
402
| ExprKind :: Tuple { .. }
415
403
| ExprKind :: Index { .. }
416
404
| ExprKind :: Field { .. }
@@ -521,12 +509,6 @@ where
521
509
recurse ( tcx, ct. subtree ( func) , f) ?;
522
510
args. iter ( ) . try_for_each ( |& arg| recurse ( tcx, ct. subtree ( arg) , f) )
523
511
}
524
- Node :: Block ( stmts, opt_expr) => {
525
- for id in stmts. iter ( ) . copied ( ) . chain ( opt_expr) {
526
- recurse ( tcx, ct. subtree ( id) , f) ?;
527
- }
528
- ControlFlow :: CONTINUE
529
- }
530
512
Node :: Cast ( operand, _) => recurse ( tcx, ct. subtree ( operand) , f) ,
531
513
}
532
514
}
@@ -615,19 +597,8 @@ pub(super) fn try_unify<'tcx>(
615
597
{
616
598
try_unify ( tcx, a. subtree ( a_operand) , b. subtree ( b_operand) )
617
599
}
618
- ( Node :: Block ( a_stmts, a_opt_expr) , Node :: Block ( b_stmts, b_opt_expr) )
619
- if a_stmts. len ( ) == b_stmts. len ( ) => {
620
- a_stmts. iter ( ) . zip ( b_stmts. iter ( ) ) . all ( |( & a_stmt, & b_stmt) | {
621
- try_unify ( tcx, a. subtree ( a_stmt) , b. subtree ( b_stmt) )
622
- } ) && match ( a_opt_expr, b_opt_expr) {
623
- ( Some ( a_expr) , Some ( b_expr) ) => try_unify ( tcx, a. subtree ( a_expr) , b. subtree ( b_expr) ) ,
624
- ( None , None ) => true ,
625
- _ => false ,
626
- }
627
- }
628
600
// use this over `_ => false` to make adding variants to `Node` less error prone
629
- ( Node :: Block ( ..) , _)
630
- | ( Node :: Cast ( ..) , _)
601
+ ( Node :: Cast ( ..) , _)
631
602
| ( Node :: FunctionCall ( ..) , _)
632
603
| ( Node :: UnaryOp ( ..) , _)
633
604
| ( Node :: Binop ( ..) , _)
0 commit comments