rust-clippy
rust-clippy copied to clipboard
default_numeric_fallback triggers on enums with an explicit repr
Summary
default_numeric_fallback
triggers on enums with a specified repr(...)
. The values are already checked by the compiler against the specified representation type and can't fallback into another type.
Might be similar to https://github.com/rust-lang/rust-clippy/issues/9632, but I'm guessing will require a separate fix.
Lint Name
default_numeric_fallback
Reproducer
I tried this code:
#![warn(clippy::default_numeric_fallback)]
#[repr(i32)]
pub enum State {
Error = -1,
Idle = 0,
Waiting = 1,
Done = 2,
}
I saw this happen:
warning: default numeric fallback might occur
--> src/lib.rs:5:14
|
5 | Error = -1,
| ^ help: consider adding suffix: `1_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:1:9
|
1 | #![warn(clippy::default_numeric_fallback)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: default numeric fallback might occur
--> src/lib.rs:6:12
|
6 | Idle = 0,
| ^ help: consider adding suffix: `0_i32`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
warning: default numeric fallback might occur
--> src/lib.rs:7:15
|
7 | Waiting = 1,
| ^ help: consider adding suffix: `1_i32`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
warning: default numeric fallback might occur
--> src/lib.rs:8:12
|
8 | Done = 2,
| ^ help: consider adding suffix: `2_i32`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
warning: `playground` (lib) generated 4 warnings
I expected to see this happen:
(no warning)
Version
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-pc-windows-msvc
release: 1.64.0
LLVM version: 14.0.6
Additional Labels
No response
This does not triggers anymore, playground