Skip to content

Commit 1030037

Browse files
committed
Only promote adt construction const fns
1 parent d12f35f commit 1030037

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/librustc_mir/transform/qualify_consts.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1410,12 +1410,13 @@ impl<'a, 'tcx> PromotableConstFn<'a, 'tcx> {
14101410
kind: &TerminatorKind<'tcx>,
14111411
) -> bool {
14121412
match kind {
1413-
TerminatorKind::Call { ref func, .. } => {
1413+
TerminatorKind::Call { ref func, ref args, destination: Some((dest, _)), .. } => {
14141414
let fn_ty = func.ty(mir, self.tcx);
14151415
if let ty::TyFnDef(def_id, _) = fn_ty.sty {
14161416
if self.tcx.is_const_fn(def_id) {
14171417
self.check_later(def_id);
1418-
true
1418+
args.iter().all(|op| self.check_operand(mir, op)) &&
1419+
self.check_place(mir, dest)
14191420
} else {
14201421
false
14211422
}
@@ -1426,10 +1427,6 @@ impl<'a, 'tcx> PromotableConstFn<'a, 'tcx> {
14261427
// trivial constrol flow
14271428
TerminatorKind::Goto { .. } |
14281429
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),
14331430
// everything else is not promotable
14341431
_ => false,
14351432
}
@@ -1493,23 +1490,24 @@ impl<'a, 'tcx> PromotableConstFn<'a, 'tcx> {
14931490
match rvalue {
14941491
| Rvalue::Use(op)
14951492
| Rvalue::Repeat(op, _)
1496-
| Rvalue::UnaryOp(_, op)
14971493
=> self.check_operand(mir, op),
14981494

14991495
Rvalue::NullaryOp(..) => true,
15001496

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+
15031505
| Rvalue::Ref(_, _, place)
15041506
=> self.check_place(mir, place),
15051507

15061508
| Rvalue::Aggregate(_, operands)
15071509
=> operands.iter().any(|op| self.check_operand(mir, op)),
15081510

1509-
| Rvalue::BinaryOp(_, a, b)
1510-
| Rvalue::CheckedBinaryOp(_, a, b)
1511-
=> self.check_operand(mir, a) && self.check_operand(mir, b),
1512-
15131511
| Rvalue::Cast(CastKind::ReifyFnPointer, op, _)
15141512
| Rvalue::Cast(CastKind::UnsafeFnPointer, op, _)
15151513
| Rvalue::Cast(CastKind::ClosureFnPointer, op, _)

0 commit comments

Comments
 (0)