Skip to content

Nightly rejects panic!(..) invocation which is accepted by stable with "cannot call non-const formatting macro in constants" #140585

Closed
@horazont

Description

@horazont

Code

I tried this code:

const _: () = {
    if false {
        panic!("hello world: {}", "foo");  // works only in stable
    }
};

Playground

I expected to see this happen: Compiles without error.

Instead, this happened:

   Compiling playground v0.0.1 (/playground)
error[E0015]: cannot call non-const formatting macro in constants
 --> src/lib.rs:3:9
  |
3 |         panic!("hello world: {}", "foo");  // works only in stable
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: calls in constants are limited to constant functions, tuple structs and tuple variants

Version it worked on

It most recently worked on: 1.87 (beta).

Version with regression

rustc --version --verbose:

~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --version --verbose
rustc 1.88.0-nightly (3350c1eb3 2025-05-01)
binary: rustc
commit-hash: 3350c1eb3fd8fe1bee1ed4c76944d707bd256876
commit-date: 2025-05-01
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API 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