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

Cast_ptr_alignment false negative in trait method default impl #3440

Open
dtolnay opened this issue Nov 21, 2018 · 0 comments
Open

Cast_ptr_alignment false negative in trait method default impl #3440

dtolnay opened this issue Nov 21, 2018 · 0 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-negative Issue: The lint should have been triggered on code, but wasn't L-correctness Lint: Belongs in the correctness lint group

Comments

@dtolnay
Copy link
Member

dtolnay commented Nov 21, 2018

I believe Clippy should catch both of the following casts but it currently only flags the first one.

unsafe fn frob(bytes: *const u8) -> *const String {
    // Correctly caught by cast_ptr_alignment.
    bytes as *const String
}

trait Trait {
    unsafe fn frob(bytes: *const u8) -> *const Self where Self: Sized {
        // Should be caught but is not.
        bytes as *const Self
    }
}

Would have prevented this bug in Chrome OS: https://bugs.chromium.org/p/chromium/issues/detail?id=900962.

clippy 0.0.212 (f5d868c 2018-11-15)

@oli-obk oli-obk added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-correctness Lint: Belongs in the correctness lint group labels Nov 21, 2018
@rustbot rustbot added the I-false-negative Issue: The lint should have been triggered on code, but wasn't label Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-negative Issue: The lint should have been triggered on code, but wasn't L-correctness Lint: Belongs in the correctness lint group
Projects
None yet
Development

No branches or pull requests

3 participants