Skip to content

CTFE: nullary function memoization munges backtraces #75390

Closed
@RalfJung

Description

@RalfJung

This code:

#![feature(const_panic)]
#![feature(const_fn)]

const fn foo(x: i32) {
    panic!();
}

const fn bar(x: i32) { foo(x) }

const _:() = bar(13);

produces a fairly reasonable error:

error: any use of this value will cause an error
  --> src/lib.rs:5:5
   |
5  |     panic!();
   |     ^^^^^^^^^
   |     |
   |     the evaluated program panicked at 'explicit panic', src/lib.rs:5:5
   |     inside `foo` at /rustc/770bd3d1d03f0de2e27b1ae6a0604597d0e26f84/library/std/src/macros.rs:13:23
   |     inside `bar` at src/lib.rs:8:24
   |     inside `_` at src/lib.rs:10:14
...
10 | const _:() = bar(13);
   | ---------------------
   |
   = note: `#[deny(const_err)]` on by default
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

However, when I remove the dummy argument x, I get the following set of three separate errors:

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:5:5
  |
5 |     panic!();
  |     ^^^^^^^^^ the evaluated program panicked at 'explicit panic', src/lib.rs:5:5
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:8:18
  |
8 | const fn bar() { foo() }
  |                  ^^^^^ referenced constant has errors

error: any use of this value will cause an error
  --> src/lib.rs:10:14
   |
10 | const _:() = bar();
   | -------------^^^^^-
   |              |
   |              referenced constant has errors
   |
   = note: `#[deny(const_err)]` on by default

All the information is still there, but it is now not clear at all that this is in fact just a single const-eval stacktrace we are seeing here.

Cc @rust-lang/wg-const-eval

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-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