From f4a3e50d782c609f0868d06fc2b03fbea6774a2f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 4 Sep 2018 16:09:30 +0200 Subject: Update rustdoc test --- src/test/rustdoc/const-evalutation-ice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/rustdoc') diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs index 000ed709a8a..5675f61bd4b 100644 --- a/src/test/rustdoc/const-evalutation-ice.rs +++ b/src/test/rustdoc/const-evalutation-ice.rs @@ -17,4 +17,4 @@ pub struct S { s: Cell } -pub type _S = [usize; 0 - (mem::size_of::() != 4) as usize]; +pub const N: usize = 0 - (mem::size_of::() != 4) as usize; -- cgit 1.4.1-3-g733a5 From 7c34f2da577a0b3b8effdbcc0705499bc2a6861f Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Tue, 18 Sep 2018 04:26:39 +0100 Subject: Addressed minor issues brought up in review. --- src/librustc_mir/const_eval.rs | 15 +++++++++------ src/test/rustdoc/const-evalutation-ice.rs | 2 +- .../const-eval/promoted_const_fn_fail_deny_const_err.rs | 10 ++++------ .../promoted_const_fn_fail_deny_const_err.stderr | 3 +-- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/test/rustdoc') 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 - -- cgit 1.4.1-3-g733a5 From 7717a63182722b33d9c5c298157d54eaaf23dab2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Sep 2018 09:30:25 +0200 Subject: fix a test comment --- src/test/rustdoc/const-evalutation-ice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/rustdoc') diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs index 64a20d49876..1c04c34ea68 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 we don't get an ICE for the S type. +// Just check we don't get an ICE for `N`. use std::cell::Cell; use std::mem; -- cgit 1.4.1-3-g733a5