Skip to content

cast_possible_truncation false negative when casting u32usize #16226

@xtqqczze

Description

@xtqqczze

Summary

clippy::cast_possible_truncation fails to warn when casting u32 to usize even though truncation is possible on platforms where usize is narrower than 32 bits (e.g., 16-bit pointer-width targets).

Lint Name

cast_possible_truncation

Reproducer

I tried this code:

#[deny(clippy::cast_possible_truncation)]
pub fn as_usize(x: u32) -> usize {
    x as usize
}

I expected to see this happen:

error: casting `u32` to `usize` may truncate the value on targets with 16-bit wide pointers

Instead, this happened:

lint did not fire

Version


Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions