about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Regueiro <alexreg@me.com>2018-09-18 04:26:39 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-10-25 16:47:35 +0200
commit7c34f2da577a0b3b8effdbcc0705499bc2a6861f (patch)
treec94f3c2d55d6ac78bf93d523a8e04c922a471b5f
parentbf8471aeda0a00c37a4798942ef9d5ae551eef20 (diff)
downloadrust-7c34f2da577a0b3b8effdbcc0705499bc2a6861f.tar.gz
rust-7c34f2da577a0b3b8effdbcc0705499bc2a6861f.zip
Addressed minor issues brought up in review.
-rw-r--r--src/librustc_mir/const_eval.rs15
-rw-r--r--src/test/rustdoc/const-evalutation-ice.rs2
-rw-r--r--src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs10
-rw-r--r--src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr3
4 files changed, 15 insertions, 15 deletions
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs
index 5cda7154774..c501ef8eceb 100644
--- a/src/librustc_mir/const_eval.rs
+++ b/src/librustc_mir/const_eval.rs
@@ -597,12 +597,14 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
 ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
-    // so we do a small trick here. We check whether we can evaluate the constant in the more
-    // restrictive `Reveal::UserFacing`, which most likely already was computed. In a large
-    // percentage of constants that will already have succeeded. Only associated constants of
-    // generic functions will fail due to not enough monomorphization information being available
-
-    // in case we fail in the `UserFacing` variant, we just do the real computation.
+    // Because the constant is computed twice (once per value of `Reveal`), we are at risk of
+    // reporting the same error twice here. To resolve this, we check whether we can evaluate the
+    // constant in the more restrictive `Reveal::UserFacing`, which most likely already was
+    // computed. For a large percentage of constants that will already have succeeded. Only
+    // associated constants of generic functions will fail due to not enough monomorphization
+    // information being available.
+
+    // In case we fail in the `UserFacing` variant, we just do the real computation.
     if key.param_env.reveal == Reveal::All {
         let mut key = key.clone();
         key.param_env.reveal = Reveal::UserFacing;
@@ -614,6 +616,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
         }
     }
     trace!("const eval: {:?}", key);
+
     let cid = key.value;
     let def_id = cid.instance.def.def_id();
 
diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs
index 5675f61bd4b..64a20d49876 100644
--- a/src/test/rustdoc/const-evalutation-ice.rs
+++ b/src/test/rustdoc/const-evalutation-ice.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// Just check if we don't get an ICE for the _S type.
+// Just check we don't get an ICE for the S type.
 
 use std::cell::Cell;
 use std::mem;
diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
index 9f19e68f2a8..dca8f3c4745 100644
--- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
+++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
@@ -19,17 +19,15 @@ union Bar {
 
 const fn bar() -> u8 {
     unsafe {
-        // this will error as long as this test
-        // is run on a system whose pointers need more
-        // than 8 bits
+        // This will error as long as this test is run on a system whose
+        // pointers need more than 8 bits.
         Bar { a: &42 }.b as u8
     }
 }
 
 fn main() {
-    // FIXME(oli-obk): this should panic at runtime
-    // this will actually compile, but then
-    // abort at runtime (not panic, hard abort).
+    // This will compile, but then hard-abort at runtime.
+    // FIXME(oli-obk): this should instead panic (not hard-abort) at runtime.
     let x: &'static u8 = &(bar() + 1);
     let y = *x;
     unreachable!();
diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr
index 3eeacbf842a..8e21f909954 100644
--- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr
+++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr
@@ -1,5 +1,5 @@
 error: reaching this expression at runtime will panic or abort
-  --> $DIR/promoted_const_fn_fail_deny_const_err.rs:33:26
+  --> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:26
    |
 LL |         Bar { a: &42 }.b as u8
    |         ---------------------- a raw memory access tried to access part of a pointer value as raw bytes
@@ -16,4 +16,3 @@ LL | #![deny(const_err)]
    |         ^^^^^^^^^
 
 error: aborting due to previous error
-