Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_numeric_fallback triggers on enums with an explicit repr #9656

Closed
RReverser opened this issue Oct 15, 2022 · 1 comment
Closed

default_numeric_fallback triggers on enums with an explicit repr #9656

RReverser opened this issue Oct 15, 2022 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@RReverser
Copy link

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 #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

@RReverser RReverser added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 15, 2022
@J-ZhengLi
Copy link
Member

This does not triggers anymore, playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants