Closed
Description
I tried this code:
println!("{}", 0xdead_beefu32)
I expected to see this happen: no warnings, the decimal conversion is printed.
Instead, this happened:
warning: literal with an empty format string
--> src/main.rs:2:20
|
2 | println!("{}", 0xdead_beefu32)
| ^^^^^^^^^^^^^^
|
= note: `#[warn(clippy::print_literal)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#print_literal
The same issue appears with float literals. The problem is that the source code representation need not equate the printed number in any obvious way. As hopefully shown by the example above, there are a number of conversion applied to literals that might make their decimal Display representation rather non-obvious. The motivation for the source code representation is entirely different, showing rather how they might be derive or related to a specification document. Examples where the source representation is different than the Display one include:
1.200
to show the number of significant digits of a constant.0b11001
for numbers with bit flags.1_000_001
as recommended for splitting long numbers.123.0E+77
for engineering numbers.