Closed
Description
Summary
Since constants require type annotations, there's no reason for clippy to complain about lack of type information of literals in constants.
|
10 | const AVERAGE_DAYS_IN_YEAR: f64 = 365.2425;
| ^^^^^^^^ help: consider adding suffix: `365.242_5_f64`
|
= note: `-D clippy::default-numeric-fallback` implied by `-D clippy::restriction`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
Lint Name
default_numeric_fallback
Reproducer
I tried this code:
const AVERAGE_DAYS_IN_YEAR: f64 = 365.2425;
fn main() {
println!("Hello, world!");
println!("{}", AVERAGE_DAYS_IN_YEAR);
}
I saw this happen:
$ cargo clippy -- -D clippy::default-numeric-fallback
Checking clippy-numeric-fallback-test v0.1.0 (/tmp/clippy-numeric-fallback-test)
error: default numeric fallback might occur
--> src/main.rs:1:35
|
1 | const AVERAGE_DAYS_IN_YEAR: f64 = 365.2425;
| ^^^^^^^^ help: consider adding suffix: `365.242_5_f64`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
= note: requested on the command line with `-D clippy::default-numeric-fallback`
error: could not compile `clippy-numeric-fallback-test` due to previous error
I expected to see this happen:
no errors
Version
rustc 1.66.0-nightly (a6b7274a4 2022-10-10)
binary: rustc
commit-hash: a6b7274a462829f8ef08a1ddcdcec7ac80dbf3e1
commit-date: 2022-10-10
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
Additional Labels
No response