Skip to content

Commit 7c34f2d

Browse files
Alexander Regueirooli-obk
authored andcommitted
Addressed minor issues brought up in review.
1 parent bf8471a commit 7c34f2d

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,14 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
597597
tcx: TyCtxt<'a, 'tcx, 'tcx>,
598598
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
599599
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
600-
// so we do a small trick here. We check whether we can evaluate the constant in the more
601-
// restrictive `Reveal::UserFacing`, which most likely already was computed. In a large
602-
// percentage of constants that will already have succeeded. Only associated constants of
603-
// generic functions will fail due to not enough monomorphization information being available
604-
605-
// in case we fail in the `UserFacing` variant, we just do the real computation.
600+
// Because the constant is computed twice (once per value of `Reveal`), we are at risk of
601+
// reporting the same error twice here. To resolve this, we check whether we can evaluate the
602+
// constant in the more restrictive `Reveal::UserFacing`, which most likely already was
603+
// computed. For a large percentage of constants that will already have succeeded. Only
604+
// associated constants of generic functions will fail due to not enough monomorphization
605+
// information being available.
606+
607+
// In case we fail in the `UserFacing` variant, we just do the real computation.
606608
if key.param_env.reveal == Reveal::All {
607609
let mut key = key.clone();
608610
key.param_env.reveal = Reveal::UserFacing;
@@ -614,6 +616,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
614616
}
615617
}
616618
trace!("const eval: {:?}", key);
619+
617620
let cid = key.value;
618621
let def_id = cid.instance.def.def_id();
619622

src/test/rustdoc/const-evalutation-ice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Just check if we don't get an ICE for the _S type.
11+
// Just check we don't get an ICE for the S type.
1212

1313
use std::cell::Cell;
1414
use std::mem;

src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ union Bar {
1919

2020
const fn bar() -> u8 {
2121
unsafe {
22-
// this will error as long as this test
23-
// is run on a system whose pointers need more
24-
// than 8 bits
22+
// This will error as long as this test is run on a system whose
23+
// pointers need more than 8 bits.
2524
Bar { a: &42 }.b as u8
2625
}
2726
}
2827

2928
fn main() {
30-
// FIXME(oli-obk): this should panic at runtime
31-
// this will actually compile, but then
32-
// abort at runtime (not panic, hard abort).
29+
// This will compile, but then hard-abort at runtime.
30+
// FIXME(oli-obk): this should instead panic (not hard-abort) at runtime.
3331
let x: &'static u8 = &(bar() + 1);
3432
let y = *x;
3533
unreachable!();

src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: reaching this expression at runtime will panic or abort
2-
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:33:26
2+
--> $DIR/promoted_const_fn_fail_deny_const_err.rs:31:26
33
|
44
LL | Bar { a: &42 }.b as u8
55
| ---------------------- a raw memory access tried to access part of a pointer value as raw bytes
@@ -16,4 +16,3 @@ LL | #![deny(const_err)]
1616
| ^^^^^^^^^
1717

1818
error: aborting due to previous error
19-

0 commit comments

Comments
 (0)