Skip to content
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

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

Closed
Shnatsel opened this issue Mar 1, 2022 · 3 comments
Closed
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Shnatsel
Copy link
Member

Shnatsel commented Mar 1, 2022

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
@Shnatsel Shnatsel added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Mar 1, 2022
@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed regression-untriaged Untriaged performance or correctness regression. labels Mar 1, 2022
Shnatsel added a commit to rustsec/rustsec that referenced this issue Mar 1, 2022
@PatchMixolydic
Copy link
Contributor

This appears to have been an intentional bugfix to bring unreachable! in line with other panic macros. See also #92137, the original report of this macro exhibiting Rust 2015-like behaviour in Rust 2021.

zslayton added a commit to amazon-ion/ion-cli that referenced this issue Mar 2, 2022
Starting in Rust 1.59, calls to the `unreachable!` macro no longer
accept string variables as their first parameter. This brings their
behavior in line with macros like `println!`, `format!`, and `write!`.

See: rust-lang/rust#94475
zslayton added a commit to amazon-ion/ion-cli that referenced this issue Mar 2, 2022
Starting in Rust 1.59, calls to the `unreachable!` macro no longer
accept string variables as their first parameter. This brings their
behavior in line with macros like `println!`, `format!`, and `write!`.

See: rust-lang/rust#94475
@jyn514
Copy link
Member

jyn514 commented Mar 3, 2022

Why was there no future-incompat warning for this? The first time I saw it was when a stable compiler upgrade broke my code.

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 3, 2022
@camelid
Copy link
Member

camelid commented Mar 3, 2022

Closing this issue as intended behavior.

@camelid camelid closed this as completed Mar 3, 2022
@camelid camelid removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 3, 2022
tarcieri pushed a commit to rustsec/rustsec that referenced this issue Apr 16, 2022
boustrophedon added a commit to boustrophedon/rss-actions that referenced this issue Oct 13, 2022
- use format string directly in unreachable! call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants