Error in Format!


const PI : f64 = 3.164;
fn main() {

error: format argument must be a string literal
--> src/
3 | println!(PI);
| ^^
help: you might be missing a string literal to format with
3 | println!("{}", PI);
| ^^^^^

It is exactly what the error says. This is because the macro expects the first argument to be definition how to display things (the formatting string). The macro wants to have access to the formatting string immediately when the macro is expanded. Variables and constants are not supported, because they don't exist yet when macros are expanded (macros run before everything else). The first argument has to be string literal directly.

Your compiler error message is from an older version of your code: it thinks line 3 is


but you listed it as


Can you update your post to include the correct error message? Also, please use code blocks to make your post more readable, as described in the pinned post:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.