-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
println!
accepts non-string literals as the format string:
fn main() {
println!(12.3);
}
print!
does not:
fn main() {
print!(12.3);
}
error: format argument must be a string literal.
--> src/main.rs:2:12
|
2 | print!(12.3);
| ^^^^
This is because println!
is implemented as calling print!
with the result of concat!
:
https://github.com/rust-lang/rust/blob/1.23.0/src/libstd/macros.rs#L150-L154
print!
just calls format_args
:
https://github.com/rust-lang/rust/blob/1.23.0/src/libstd/macros.rs#L119-L121
However, concat!
stringifies its argument:
This means that the "format string" can be any of:
- string literal
- floating point literal
- character literal
- integer literal
- boolean literal
Metadata
Metadata
Assignees
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.