Skip to content

Const-eval failure in const fn does not print the path of what we evaluate #142010

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

Closed
RalfJung opened this issue Jun 4, 2025 · 0 comments · Fixed by #142015
Closed

Const-eval failure in const fn does not print the path of what we evaluate #142010

RalfJung opened this issue Jun 4, 2025 · 0 comments · Fixed by #142015
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 4, 2025

Consider this code:

struct S<T>(T);

const fn oopsie() -> ! {
    panic!();
}

impl<T> S<T> {
    const C1: i32 = panic!();
    const C2: i32 = oopsie();
}

fn main() {
    S::<i32>::C1; // or C2
}

If we use C1, we get the following:

error[E0080]: evaluation of `S::<i32>::C1` failed
 --> src/main.rs:8:21
  |
8 |     const C1: i32 = panic!();
  |                     ^^^^^^^^ evaluation panicked: explicit panic

But if we use C2, we get:

error[E0080]: evaluation of `oopsie` failed
 --> src/main.rs:9:21
  |
9 |     const C2: i32 = oopsie();
  |                     ^^^^^^^^ evaluation panicked: explicit panic
  |
note: inside `oopsie`
 --> src/main.rs:4:5
  |
4 |     panic!();
  |     ^^^^^^^^ the failure occurred here

Note that it says "evaluation of oopsie failed"; I would have expected "evaluation of S::<i32>::C2 failed". That's where the span points at, too.

Cc @oli-obk

@RalfJung RalfJung added the C-bug Category: This is a bug. label Jun 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 4, 2025
@fmease fmease added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 5, 2025
Report the actual item that evaluation failed for

instead of id of the last frame in the evaluation stack

r? `@RalfJung`

fixes rust-lang#142010
@bors bors closed this as completed in 0820dd0 Jun 5, 2025
rust-timer added a commit that referenced this issue Jun 5, 2025
Rollup merge of #142015 - oli-obk:wrong-instance, r=RalfJung

Report the actual item that evaluation failed for

instead of id of the last frame in the evaluation stack

r? ``@RalfJung``

fixes #142010
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jun 6, 2025
Report the actual item that evaluation failed for

instead of id of the last frame in the evaluation stack

r? ``@RalfJung``

fixes rust-lang/rust#142010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants