Addressed minor issues brought up in review.

This commit is contained in:
Alexander Regueiro 2018-09-18 04:26:39 +01:00 committed by Oliver Scherer
parent bf8471aeda
commit 7c34f2da57
4 changed files with 14 additions and 14 deletions

View File

@ -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
// 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.
// 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();

View File

@ -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;

View File

@ -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!();

View File

@ -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