@@ -1410,12 +1410,13 @@ impl<'a, 'tcx> PromotableConstFn<'a, 'tcx> {
1410
1410
kind : & TerminatorKind < ' tcx > ,
1411
1411
) -> bool {
1412
1412
match kind {
1413
- TerminatorKind :: Call { ref func, .. } => {
1413
+ TerminatorKind :: Call { ref func, ref args , destination : Some ( ( dest , _ ) ) , .. } => {
1414
1414
let fn_ty = func. ty ( mir, self . tcx ) ;
1415
1415
if let ty:: TyFnDef ( def_id, _) = fn_ty. sty {
1416
1416
if self . tcx . is_const_fn ( def_id) {
1417
1417
self . check_later ( def_id) ;
1418
- true
1418
+ args. iter ( ) . all ( |op| self . check_operand ( mir, op) ) &&
1419
+ self . check_place ( mir, dest)
1419
1420
} else {
1420
1421
false
1421
1422
}
@@ -1426,10 +1427,6 @@ impl<'a, 'tcx> PromotableConstFn<'a, 'tcx> {
1426
1427
// trivial constrol flow
1427
1428
TerminatorKind :: Goto { .. } |
1428
1429
TerminatorKind :: Return => true ,
1429
- // currently disallowed
1430
- TerminatorKind :: SwitchInt { .. } => false ,
1431
- // assertions are fine, they are essentially "goto or abort"
1432
- TerminatorKind :: Assert { cond, .. } => self . check_operand ( mir, cond) ,
1433
1430
// everything else is not promotable
1434
1431
_ => false ,
1435
1432
}
@@ -1493,23 +1490,24 @@ impl<'a, 'tcx> PromotableConstFn<'a, 'tcx> {
1493
1490
match rvalue {
1494
1491
| Rvalue :: Use ( op)
1495
1492
| Rvalue :: Repeat ( op, _)
1496
- | Rvalue :: UnaryOp ( _, op)
1497
1493
=> self . check_operand ( mir, op) ,
1498
1494
1499
1495
Rvalue :: NullaryOp ( ..) => true ,
1500
1496
1501
- | Rvalue :: Len ( place)
1502
- | Rvalue :: Discriminant ( place)
1497
+ // disallow anything that processes the bits of a value
1498
+ | Rvalue :: UnaryOp ( _, _)
1499
+ | Rvalue :: Len ( _)
1500
+ | Rvalue :: Discriminant ( _)
1501
+ | Rvalue :: BinaryOp ( _, _, _)
1502
+ | Rvalue :: CheckedBinaryOp ( _, _, _)
1503
+ => false ,
1504
+
1503
1505
| Rvalue :: Ref ( _, _, place)
1504
1506
=> self . check_place ( mir, place) ,
1505
1507
1506
1508
| Rvalue :: Aggregate ( _, operands)
1507
1509
=> operands. iter ( ) . any ( |op| self . check_operand ( mir, op) ) ,
1508
1510
1509
- | Rvalue :: BinaryOp ( _, a, b)
1510
- | Rvalue :: CheckedBinaryOp ( _, a, b)
1511
- => self . check_operand ( mir, a) && self . check_operand ( mir, b) ,
1512
-
1513
1511
| Rvalue :: Cast ( CastKind :: ReifyFnPointer , op, _)
1514
1512
| Rvalue :: Cast ( CastKind :: UnsafeFnPointer , op, _)
1515
1513
| Rvalue :: Cast ( CastKind :: ClosureFnPointer , op, _)
0 commit comments