about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-02-10 15:58:10 +0100
committerRalf Jung <post@ralfj.de>2020-02-13 11:04:26 +0100
commit7e7d1c39edafcbce55ba08449689566e335545b7 (patch)
treefe60bccd5db2d702570b815b9c48ee58ebcd05d2
parent55339f2eb7c186334216c35203f98540e8c8cb37 (diff)
downloadrust-7e7d1c39edafcbce55ba08449689566e335545b7.tar.gz
rust-7e7d1c39edafcbce55ba08449689566e335545b7.zip
improve comments:
- comment for special handling of Shl/Shr
- reference a PR
-rw-r--r--src/librustc/mir/interpret/error.rs1
-rw-r--r--src/librustc_mir/transform/const_prop.rs12
2 files changed, 9 insertions, 4 deletions
diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs
index 64d32690545..e747eee30f9 100644
--- a/src/librustc/mir/interpret/error.rs
+++ b/src/librustc/mir/interpret/error.rs
@@ -182,6 +182,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
         if must_error {
             // The `message` makes little sense here, this is a more serious error than the
             // caller thinks anyway.
+            // See <https://github.com/rust-lang/rust/pull/63152>.
             finish(struct_error(tcx, &err_msg), None);
         } else {
             // Regular case.
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index c8d832814c7..952dede4a15 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -527,6 +527,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
             let (_res, overflow, _ty) = this.ecx.overflowing_unary_op(op, val)?;
             Ok(overflow)
         })? {
+            // `AssertKind` only has an `OverflowNeg` variant, to make sure that is
+            // appropriate to use.
             assert_eq!(op, UnOp::Neg, "Neg is the only UnOp that can overflow");
             self.report_panic_as_lint(source_info, PanicInfo::OverflowNeg)?;
         }
@@ -544,6 +546,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
     ) -> Option<()> {
         let r =
             self.use_ecx(|this| this.ecx.read_immediate(this.ecx.eval_operand(right, None)?))?;
+        // Check for exceeding shifts *even if* we cannot evaluate the LHS.
         if op == BinOp::Shr || op == BinOp::Shl {
             let left_bits = place_layout.size.bits();
             let right_size = r.layout.size;
@@ -564,7 +567,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
         }
 
         // The remaining operators are handled through `overflowing_binary_op`.
-        // FIXME: Why do we not also do this for `Shr` and `Shl`?
         if self.use_ecx(|this| {
             let l = this.ecx.read_immediate(this.ecx.eval_operand(left, None)?)?;
             let (_res, overflow, _ty) = this.ecx.overflowing_binary_op(op, l, r)?;
@@ -603,9 +605,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
         //   2. Working around bugs in other parts of the compiler
         //        - In this case, we'll return `None` from this function to stop evaluation.
         match rvalue {
-            // Additional checking: if overflow checks are disabled (which is usually the case in
-            // release mode), then we need to do additional checking here to give lints to the user
-            // if an overflow would occur.
+            // Additional checking: give lints to the user if an overflow would occur.
+            // If `overflow_check` is set, running const-prop on the `Assert` terminators
+            // will already generate the appropriate messages.
             Rvalue::UnaryOp(op, arg) if !overflow_check => {
                 trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);
                 self.check_unary_op(*op, arg, source_info)?;
@@ -613,6 +615,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
 
             // Additional checking: check for overflows on integer binary operations and report
             // them to the user as lints.
+            // If `overflow_check` is set, running const-prop on the `Assert` terminators
+            // will already generate the appropriate messages.
             Rvalue::BinaryOp(op, left, right) if !overflow_check => {
                 trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right);
                 self.check_binary_op(*op, left, right, source_info, place_layout)?;