Skip to content

const-eval error: always say in which item the error occurred #142008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jun 4, 2025

I don't see why "is this generic" should make a difference. It may be reasonable to key this on whether the error occurs in a const fn that was invoked by a const (making it non-obvious which constant it is) vs inside the body of the const.

r? @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@@ -2,7 +2,7 @@ error[E0080]: attempt to compute `u8::MAX + 1_u8`, which would overflow
--> $DIR/default-param-wf-concrete.rs:4:28
|
LL | struct Foo<const N: u8 = { 255 + 1 }>;
| ^^^^^^^ evaluation of constant value failed here
| ^^^^^^^ evaluation of `Foo::{constant#0}` failed here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't great, ideally it'd say something like "evaluation of unnamed constant inside Foo failed here" or so...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, this may be sth we want to improve for all mentions of unnamed consts. The disambiguators don't help anyone but compiler devs.

@@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic
--> $DIR/issue-81899.rs:6:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^ evaluation of `f::<{closure@$DIR/issue-81899.rs:6:31: 6:34}>` failed here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure why this doesn't say _CONST...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, we take the instance from the top of the stack. Possibly a remnant from early miri days? We should just take the current item's global id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found where in the code we do that...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we don't. huh. This is very weird. Even if some promotion thing were going on, we should be reporting the promoted in that case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, you're sharing my confusion now. ;)

I can only look at this more closely next weekend -- I thought this would be a largely editorial change.^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lmao I found it

impl Subdiagnostic for FrameNote {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
diag.arg("times", self.times);
diag.arg("where_", self.where_);
diag.arg("instance", self.instance);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, this is nasty form of global state...

@@ -2,7 +2,7 @@ error[E0080]: writing to ALLOC0 which is read-only
--> $DIR/issue-100313.rs:18:5
|
LL | x.set_false();
| ^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^ evaluation of `T::<&true>::set_false` failed here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this use the name of the function rather than the name of the surrounding constant...?

@@ -14,7 +14,7 @@ error[E0080]: calling non-const function `double`
--> $DIR/const_fn_ptr_fail2.rs:19:18
|
LL | const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
| ^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^ evaluation of `bar` failed here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I think this is just using the wrong instance? It seems to be the instance of the top frame, rather than the surrounding constant.

I entirely forgot that we print the backtrace backwards now. Still not sure if that's really a good idea. But that means the error itself always points inside the constant, right? So maybe there's no reason to put the constant name in the error message after all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah something is very odd here: #142010

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/function_calls/exported_symbol_bad_unwind2.rs (revision `definition`) ... ok
tests/fail/function_calls/exported_symbol_bad_unwind2.rs (revision `both`) ... ok

FAILED TEST: tests/fail/const-ub-checks.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-9em7Vp" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail" "tests/fail/const-ub-checks.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/const-ub-checks.stderr` to the actual output
--- tests/fail/const-ub-checks.stderr
+++ <stderr output>
---
   |
LL |     let _x = UNALIGNED_READ;
   |              ^^^^^^^^^^^^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.

---
   |
LL |     let _x = UNALIGNED_READ;
   |              ^^^^^^^^^^^^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.

full stdout:



FAILED TEST: tests/fail/erroneous_const2.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-9em7Vp" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail" "tests/fail/erroneous_const2.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/erroneous_const2.stderr` to the actual output
--- tests/fail/erroneous_const2.stderr
+++ <stderr output>
---
   |
LL |     println!("{}", FOO);
   |                    ^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
  --> tests/fail/erroneous_const2.rs:8:20
   |
LL |     println!("{}", FOO);
---
   |
LL |     println!("{}", FOO);
   |                    ^^^
   |
   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
  --> tests/fail/erroneous_const2.rs:8:20
   |
LL |     println!("{}", FOO);
---

Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.29.2/src/lib.rs:369

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/ui-f58affc77002becb` (exit status: 1)
Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:05:06
  local time: Wed Jun  4 07:50:36 UTC 2025
  network time: Wed, 04 Jun 2025 07:50:36 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@RalfJung
Copy link
Member Author

RalfJung commented Jun 4, 2025

Once #142015 lands, do we even still want this? The first label always points inside the "root constant" (I forgot about that), so we don't have to repeat the name of that constant.

It's kind of unnecessary that we spell out whether it's a static or const but 🤷

@oli-obk
Copy link
Contributor

oli-obk commented Jun 4, 2025

I think we still want this PR just as a simplification without any downsides

@bors
Copy link
Collaborator

bors commented Jun 5, 2025

☔ The latest upstream changes (presumably #142081) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants