Closed
Description
Reproduced in the Playground on 1.58.1 stable.
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fe56b4c08a046bd087207e0649379a33
const fn failure() {
panic!("{:?}", 0);
}
fn main() {}
The current output is:
error[[E0658]](https://doc.rust-lang.org/stable/error-index.html#E0658): function pointer casts are not allowed in constant functions
[--> src/main.rs:2:20
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=de5939e5ea116da7ce863563832ea7b9#) |
2 | panic!("{:?}", 0);
| ^
|
= note: [see issue #57563 <https://github.com/rust-lang/rust/issues/57563>](https://github.com/rust-lang/rust/issues/57563) for more information
= note: this error originates in the macro `$crate::const_format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
error[[E0015]](https://doc.rust-lang.org/stable/error-index.html#E0015): calls in constant functions are limited to constant functions, tuple structs and tuple variants
[--> src/main.rs:2:5
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=de5939e5ea116da7ce863563832ea7b9#) |
2 | panic!("{:?}", 0);
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::const_format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
panic
with formatting isn't fully supported in const contexts, but the diagnostic is surprising, since it's not obvious that there are any function pointer casts happening. This should give a more direct message about what I've done wrong.
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Messages for errors, warnings, and lintsDiagnostics: Confusing error or lint that should be reworked.Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: Too much output caused by a single piece of incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.