Skip to content

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

@RalfJung

Description

@RalfJung

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions