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

Incorrect suggesetion in unnecessary_cast lint #8331

Closed
sunfishcode opened this issue Jan 21, 2022 · 1 comment · Fixed by #8350
Closed

Incorrect suggesetion in unnecessary_cast lint #8331

sunfishcode opened this issue Jan 21, 2022 · 1 comment · Fixed by #8350
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@sunfishcode
Copy link
Member

sunfishcode commented Jan 21, 2022

Summary

Clippy suggests changing -1_i32 as i32 to 1_i32, which produces a different value. This happens with current stable and nightly Rust.

Reproducer

I tried this code:

fn main() {
    let _ = -1_i32 as i32;
}

I expected to see clippy suggest -1_i32.

Instead, this happened:

warning: casting integer literal to `i32` is unnecessary
 --> src/main.rs:2:13
  |
2 |     let _ = -1_i32 as i32;
  |             ^^^^^^^^^^^^^ help: try: `1_i32`
  = note: `#[warn(clippy::unnecessary_cast)]` on by default

Version

rustc 1.60.0-nightly (777bb86bc 2022-01-20)
binary: rustc
commit-hash: 777bb86bcdbc568be7cff6eeeaaf81a89b4aa50b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

Additional Labels

No response

@sunfishcode sunfishcode added the C-bug Category: Clippy is not doing the correct thing label Jan 21, 2022
@dswij
Copy link
Member

dswij commented Jan 25, 2022

@rustbot claim

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants