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_fmt_panics suggestion breaks for some const functions #88429

Closed
ehuss opened this issue Aug 28, 2021 · 1 comment
Closed

non_fmt_panics suggestion breaks for some const functions #88429

ehuss opened this issue Aug 28, 2021 · 1 comment
Labels
A-edition-2021 Area: The 2021 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 28, 2021

I tried this code:

#![feature(const_panic)]
#![warn(non_fmt_panics)]
pub const fn foo(explanation: &'static str) {
    panic!(explanation);
}

This provides a suggestion to replace the code with:

    panic!("{}", explanation);

However, this will not compile in a const function:

error[E0658]: function pointer casts are not allowed in constant functions
 --> src/lib.rs:4:18
  |
4 |     panic!("{}", explanation);
  |                  ^^^^^^^^^^^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn_fn_ptr_basics)]` to the crate attributes to enable
  = note: this error originates in the macro `$crate::const_format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
 --> src/lib.rs:4:5
  |
4 |     panic!("{}", explanation);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `$crate::const_format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

I'm not actually sure what the correct suggestion should be, since panic_any is not const.

Found during the 2021 crater run for:

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (b03ccace5 2021-08-24)
binary: rustc
commit-hash: b03ccace573bb91e27625c190a0f7807045a1012
commit-date: 2021-08-24
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 13.0.0
@ehuss ehuss added C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-edition-2021 Area: The 2021 edition labels Aug 28, 2021
@m-ou-se
Copy link
Member

m-ou-se commented Aug 30, 2021

This is a known issue: #85194

Closing this, as it's part of the unstable const_panic feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2021 Area: The 2021 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.
Projects
None yet
Development

No branches or pull requests

2 participants