@@ -97,9 +97,10 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
9797
9898 ControlFlow :: CONTINUE
9999 }
100- Node :: Binop ( _, _, _) | Node :: UnaryOp ( _, _) | Node :: FunctionCall ( _, _) => {
101- ControlFlow :: CONTINUE
102- }
100+ Node :: Binop ( _, _, _)
101+ | Node :: UnaryOp ( _, _)
102+ | Node :: FunctionCall ( _, _)
103+ | Node :: Cast ( _, _, _) => ControlFlow :: CONTINUE ,
103104 } ) ;
104105
105106 match failure_kind {
@@ -304,6 +305,9 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
304305 self . nodes [ func] . used = true ;
305306 nodes. iter ( ) . for_each ( |& n| self . nodes [ n] . used = true ) ;
306307 }
308+ Node :: Cast ( _, operand, _) => {
309+ self . nodes [ operand] . used = true ;
310+ }
307311 }
308312
309313 // Nodes start as unused.
@@ -408,6 +412,12 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
408412 self . locals [ local] = self . add_node ( Node :: UnaryOp ( op, operand) , span) ;
409413 Ok ( ( ) )
410414 }
415+ Rvalue :: Cast ( cast_kind, ref operand, ty) => {
416+ let operand = self . operand_to_node ( span, operand) ?;
417+ self . locals [ local] =
418+ self . add_node ( Node :: Cast ( cast_kind, operand, ty) , span) ;
419+ Ok ( ( ) )
420+ }
411421 _ => self . error ( Some ( span) , "unsupported rvalue" ) ?,
412422 }
413423 }
@@ -594,6 +604,7 @@ where
594604 recurse ( tcx, ct. subtree ( func) , f) ?;
595605 args. iter ( ) . try_for_each ( |& arg| recurse ( tcx, ct. subtree ( arg) , f) )
596606 }
607+ Node :: Cast ( _, operand, _) => recurse ( tcx, ct. subtree ( operand) , f) ,
597608 }
598609 }
599610
@@ -676,6 +687,11 @@ pub(super) fn try_unify<'tcx>(
676687 && iter:: zip ( a_args, b_args)
677688 . all ( |( & an, & bn) | try_unify ( tcx, a. subtree ( an) , b. subtree ( bn) ) )
678689 }
690+ ( Node :: Cast ( a_cast_kind, a_operand, a_ty) , Node :: Cast ( b_cast_kind, b_operand, b_ty) )
691+ if ( a_ty == b_ty) && ( a_cast_kind == b_cast_kind) =>
692+ {
693+ try_unify ( tcx, a. subtree ( a_operand) , b. subtree ( b_operand) )
694+ }
679695 _ => false ,
680696 }
681697}
0 commit comments