-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
Clippy complains about f64
and i32
associated constants despite having : <type>
annotations.
No complains if the same declaration is used in a function, it only appears on associated constants 🤔.
Afaik, error only appears with these two types.
Reproducer
I tried this code:
#![allow(non_upper_case_globals, clippy::exhaustive_structs, dead_code)]
#![deny(clippy::default_numeric_fallback)]
pub struct Foo;
impl Foo {
const LIFE_u8: u8 = 42;
const LIFE_i8: i8 = 42;
const LIFE_u16: u16 = 42;
const LIFE_i16: i16 = 42;
const LIFE_u32: u32 = 42;
const LIFE_i32: i32 = 42;
const LIFE_u64: u64 = 42;
const LIFE_i64: i64 = 42;
const LIFE_u128: u128 = 42;
const LIFE_i128: i128 = 42;
const LIFE_usize: usize = 42;
const LIFE_isize: isize = 42;
const LIFE_f32: f32 = 42.;
const LIFE_f64: f64 = 42.;
const fn consts() {
const LIFE_u8: u8 = 42;
const LIFE_i8: i8 = 42;
const LIFE_u16: u16 = 42;
const LIFE_i16: i16 = 42;
const LIFE_u32: u32 = 42;
const LIFE_i32: i32 = 42;
const LIFE_u64: u64 = 42;
const LIFE_i64: i64 = 42;
const LIFE_u128: u128 = 42;
const LIFE_i128: i128 = 42;
const LIFE_usize: usize = 42;
const LIFE_isize: isize = 42;
const LIFE_f32: f32 = 42.;
const LIFE_f64: f64 = 42.;
}
}
Clippy then complains when the type is i32
or f64
for somer reason.
error: default numeric fallback might occur
--> src/lib.rs:12:27
|
12 | const LIFE_i32: i32 = 42;
| ^^ help: consider adding suffix: `42_i32`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![deny(clippy::default_numeric_fallback)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: default numeric fallback might occur
--> src/lib.rs:20:27
|
20 | const LIFE_f64: f64 = 42.;
| ^^^ help: consider adding suffix: `42.0_f64`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback```
### Version
```text
rustc 1.77.0-nightly (098d4fd74 2024-01-16)
binary: rustc
commit-hash: 098d4fd74c078b12bfc2e9438a2a04bc18b393bc
commit-date: 2024-01-16
host: aarch64-apple-darwin
release: 1.77.0-nightly
LLVM version: 17.0.6
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing