Skip to content

Non-literal arguments to unreachable!() are rejected starting with v1.59.0 #94475

@Shnatsel

Description

@Shnatsel

Code

I tried this code:

fn main() {
    let blah = "foobar";
    unreachable!(format!("{}", blah));
}

In 2021 edition.

On 1.58.1 this compiles, but on 1.59.0 and later it fails to build:

error: format argument must be a string literal
 --> src/main.rs:3:18
  |
3 |     unreachable!(format!("{}", blah));
  |                  ^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might be missing a string literal to format with
  |
3 |     unreachable!("{}", format!("{}", blah));
  |                  +++++

error: could not compile `format-test` due to previous error

Version it worked on

It most recently worked on: 1.58.1

Version with regression

1.59.0 stable on Rust playground, as well as the following nightly version:

rustc 1.61.0-nightly (4ce374923 2022-02-28)
binary: rustc
commit-hash: 4ce3749235fc31d15ebd444b038a9877e8c700d7
commit-date: 2022-02-28
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    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