Skip to content

unnecessary_cast false negative: parameter vs. local #13495

New issue

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

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

Already on GitHub? # to your account

Open
ojeda opened this issue Oct 3, 2024 · 1 comment
Open

unnecessary_cast false negative: parameter vs. local #13495

ojeda opened this issue Oct 3, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@ojeda
Copy link
Contributor

ojeda commented Oct 3, 2024

Summary

unnecessary_cast appears to trigger for a parameter, but not for a local.

Lint Name

unnecessary_cast

Reproducer

I tried this code:

fn g() -> i16 { 42 }

pub fn f1() -> i32 {
    let x = g();
    x as i32 as i32
}

pub fn f2(x: i16) -> i32 {
    x as i32 as i32
}

I expected to see this happen: two lints, one on each function.

Instead, this happened: one lint, only on f2.

Version

rustc 1.83.0-nightly (18b1161ec 2024-10-02)
binary: rustc
commit-hash: 18b1161ec9eeab8927f91405bca0ddf59a4a26c9
commit-date: 2024-10-02
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

@ojeda ojeda added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Oct 3, 2024
@alex-semenyuk
Copy link
Member

It seems it was done intentionally, I believe this one check

if let ExprKind::Cast(inner, ..) = expr.kind
prevent triggering

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

2 participants