@@ -102,8 +102,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
102102
103103 ControlFlow :: CONTINUE
104104 }
105- Node :: Block ( _, _)
106- | Node :: Binop ( _, _, _)
105+ Node :: Binop ( _, _, _)
107106 | Node :: UnaryOp ( _, _)
108107 | Node :: FunctionCall ( _, _) => ControlFlow :: CONTINUE ,
109108 } ) ;
@@ -288,10 +287,6 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
288287 self . nodes [ func] . used = true ;
289288 nodes. iter ( ) . for_each ( |& n| self . nodes [ n] . used = true ) ;
290289 }
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- }
295290 Node :: Cast ( operand, _) => {
296291 self . nodes [ operand] . used = true ;
297292 }
@@ -378,22 +373,14 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
378373 let arg = self . recurse_build ( arg) ?;
379374 self . add_node ( Node :: UnaryOp ( op, arg) , node. span )
380375 } ,
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) ?,
397384 // ExprKind::Use happens when a `hir::ExprKind::Cast` is a
398385 // "coercion cast" i.e. using a coercion or is a no-op.
399386 // 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> {
411398 | ExprKind :: Deref { .. }
412399 | ExprKind :: Repeat { .. }
413400 | ExprKind :: Array { .. }
401+ | ExprKind :: Block { .. }
414402 | ExprKind :: Tuple { .. }
415403 | ExprKind :: Index { .. }
416404 | ExprKind :: Field { .. }
@@ -521,12 +509,6 @@ where
521509 recurse ( tcx, ct. subtree ( func) , f) ?;
522510 args. iter ( ) . try_for_each ( |& arg| recurse ( tcx, ct. subtree ( arg) , f) )
523511 }
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- }
530512 Node :: Cast ( operand, _) => recurse ( tcx, ct. subtree ( operand) , f) ,
531513 }
532514 }
@@ -615,19 +597,8 @@ pub(super) fn try_unify<'tcx>(
615597 {
616598 try_unify ( tcx, a. subtree ( a_operand) , b. subtree ( b_operand) )
617599 }
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- }
628600 // use this over `_ => false` to make adding variants to `Node` less error prone
629- ( Node :: Block ( ..) , _)
630- | ( Node :: Cast ( ..) , _)
601+ ( Node :: Cast ( ..) , _)
631602 | ( Node :: FunctionCall ( ..) , _)
632603 | ( Node :: UnaryOp ( ..) , _)
633604 | ( Node :: Binop ( ..) , _)
0 commit comments