diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-06-03 00:41:50 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-06-19 01:47:03 -0700 |
| commit | 39788e07bae91e9974ba6879a63e4e8b97503f5b (patch) | |
| tree | 2b1d01608304f228b79e764cb41831c29dcfa604 /compiler/rustc_const_eval/src/transform | |
| parent | 8d1fa473dddd12efb2430302e5f5dfcc3eb73f8b (diff) | |
| download | rust-39788e07bae91e9974ba6879a63e4e8b97503f5b.tar.gz rust-39788e07bae91e9974ba6879a63e4e8b97503f5b.zip | |
Promote unchecked_add/sub/mul/shl/shr to mir::BinOp
Diffstat (limited to 'compiler/rustc_const_eval/src/transform')
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/promote_consts.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/validate.rs | 20 |
2 files changed, 25 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index 44b143c77f3..3802df5d3fc 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -569,13 +569,18 @@ impl<'tcx> Validator<'_, 'tcx> { | BinOp::Gt | BinOp::Offset | BinOp::Add + | BinOp::AddUnchecked | BinOp::Sub + | BinOp::SubUnchecked | BinOp::Mul + | BinOp::MulUnchecked | BinOp::BitXor | BinOp::BitAnd | BinOp::BitOr | BinOp::Shl - | BinOp::Shr => {} + | BinOp::ShlUnchecked + | BinOp::Shr + | BinOp::ShrUnchecked => {} } self.validate_operand(lhs)?; diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 3c350e25ba6..d421c7a2755 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -556,7 +556,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ); } } - Shl | Shr => { + Shl | ShlUnchecked | Shr | ShrUnchecked => { for x in [a, b] { check_kinds!( x, @@ -601,6 +601,24 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ); } } + AddUnchecked | SubUnchecked | MulUnchecked => { + for x in [a, b] { + check_kinds!( + x, + "Cannot perform unchecked arithmetic on type {:?}", + ty::Uint(..) | ty::Int(..) + ) + } + if a != b { + self.fail( + location, + format!( + "Cannot perform unchecked arithmetic on unequal types {:?} and {:?}", + a, b + ), + ); + } + } } } Rvalue::CheckedBinaryOp(op, vals) => { |
