From 618dbfab732f04f5f5b1cc170e5dbd247e4a4f8a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 11 Sep 2023 09:52:45 +0200 Subject: [PATCH 1/2] move required_consts check to general post-mono-check function --- src/helpers.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 0c7e827814..72d9dbd045 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -142,9 +142,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { fn eval_path_scalar(&self, path: &[&str]) -> Scalar { let this = self.eval_context_ref(); let instance = this.resolve_path(path, Namespace::ValueNS); - let cid = GlobalId { instance, promoted: None }; // We don't give a span -- this isn't actually used directly by the program anyway. - let const_val = this.eval_global(cid, None).unwrap_or_else(|err| { + let const_val = this.eval_global(instance).unwrap_or_else(|err| { panic!("failed to evaluate required Rust item: {path:?}\n{err:?}") }); this.read_scalar(&const_val) From 810a3c7f16234e9569d148d9226b1aab26506af7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 11 Sep 2023 23:09:11 +0200 Subject: [PATCH 2/2] don't point at const usage site for resolution-time errors also share the code that emits the actual error --- tests/fail/const-ub-checks.stderr | 2 +- tests/fail/erroneous_const.stderr | 2 +- tests/fail/erroneous_const2.stderr | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fail/const-ub-checks.stderr b/tests/fail/const-ub-checks.stderr index 596a6bb4ca..d2b9018cd4 100644 --- a/tests/fail/const-ub-checks.stderr +++ b/tests/fail/const-ub-checks.stderr @@ -4,7 +4,7 @@ error[E0080]: evaluation of constant value failed LL | ptr.read(); | ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required -note: erroneous constant used +note: erroneous constant encountered --> $DIR/const-ub-checks.rs:LL:CC | LL | let _x = UNALIGNED_READ; diff --git a/tests/fail/erroneous_const.stderr b/tests/fail/erroneous_const.stderr index 209c4a932d..cacf866393 100644 --- a/tests/fail/erroneous_const.stderr +++ b/tests/fail/erroneous_const.stderr @@ -6,7 +6,7 @@ LL | const VOID: ! = panic!(); | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) -note: erroneous constant used +note: erroneous constant encountered --> $DIR/erroneous_const.rs:LL:CC | LL | let _ = PrintName::::VOID; diff --git a/tests/fail/erroneous_const2.stderr b/tests/fail/erroneous_const2.stderr index 9aad1fc9b0..36e83b8f3b 100644 --- a/tests/fail/erroneous_const2.stderr +++ b/tests/fail/erroneous_const2.stderr @@ -4,13 +4,13 @@ error[E0080]: evaluation of constant value failed LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; | ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow -note: erroneous constant used +note: erroneous constant encountered --> $DIR/erroneous_const2.rs:LL:CC | LL | println!("{}", FOO); | ^^^ -note: erroneous constant used +note: erroneous constant encountered --> $DIR/erroneous_const2.rs:LL:CC | LL | println!("{}", FOO);