-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Error using const_format_args
in const context
#108595
Comments
I also get the same error with #![feature(const_fmt_arguments_new)]
const fn my_const_fn() {
let _ = format_args!("{}", "literal");
//panic!("{}", "literal");
}
fn main() {
my_const_fn();
} Output: $ rustc test2.rs
error[E0015]: cannot call non-const formatting macro in constant functions
--> test2.rs:4:33
|
4 | let _ = format_args!("{}", "literal");
| ^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
note: erroneous constant used
--> test2.rs:4:27
|
4 | let _ = format_args!("{}", "literal");
| ^^^^
note: erroneous constant used
--> test2.rs:4:33
|
4 | let _ = format_args!("{}", "literal");
| ^^^^^^^^^
|
= note: this note originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`. |
The reason
|
I'm closing this, because the (Unstable features without tracking issue ( |
I tried this code:
I expected to see this happen: The documentation for
const_format_args
points out that it's used for theconst_panic
feature. So I was expecting the above program to compile.Instead, this happened:
The program compiles if I replace the
const_format_args
line with the commentedpanic
line. Is this expected?Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: