Skip to content

False negative for trivial_casts with pointer #117187

Open
@Noratrieb

Description

@Noratrieb

After #113262, this will no longer fail to compile:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8ee721b21617d98d18c5256778b57efe

#[deny(trivial_casts)]
fn main() {
    let a = std::ptr::null::<()>();
    let _b = a as *const ();
}

The cast is trivial, but we miss it because we have to conservatively assume that raw pointer casts are not trivial. A possible fix would be to check for trivial raw pointer casts in MIR (but correctly considering lifetimes is still not quite easy there I think).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-raw-pointersArea: raw pointers, MaybeUninit, NonNullC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions