Skip to content

Cast_ptr_alignment false negative in trait method default impl #3440

Open
@dtolnay

Description

@dtolnay

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesI-false-negativeIssue: The lint should have been triggered on code, but wasn'tL-correctnessLint: Belongs in the correctness lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions