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

unnecessary_cast should catch unnecessary pointer cast #12738

Open
antonilol opened this issue Apr 30, 2024 · 0 comments
Open

unnecessary_cast should catch unnecessary pointer cast #12738

antonilol opened this issue Apr 30, 2024 · 0 comments
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

@antonilol
Copy link

Summary

unnecessary_cast should catch unnecessary pointer casts like &u32 to *const u32 when this would already be done implicitly

edge case to consider:
it is not always converted implicitly, like when changing the type like this: a as *const u32 as *const i32, with a: &u32

Lint Name

unnecessary_cast

Reproducer

I tried this code:

fn main() {
    let a = 123u32;
    let _: u32 = a as u32;

    let a = &123u32;
    let _: *const u32 = a as *const u32;
}

I expected to see this happen:
get a warning from the lint for both casts

Instead, this happened:
there only is a warning for the u32 -> u32 cast

Version

rustc 1.77.0 (aedd173a2 2024-03-17)
binary: rustc
commit-hash: aedd173a2c086e558c2b66d3743b344f977621a7
commit-date: 2024-03-17
host: x86_64-unknown-linux-gnu
release: 1.77.0
LLVM version: 17.0.6
@antonilol antonilol 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 Apr 30, 2024
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-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

1 participant