Skip to content

Special case overflowing literal lints to warn about -iX::MIN #108383

Open
@AaronKutch

Description

@AaronKutch

I just found several issues where people forget that -i32::MAX != i32::MIN, i32::MAX == 7fffffff while i32::MIN == -0x80000000. People see that -0x80000000 works and then mistakenly try to use +0x80000000 which doesn't work because i32 can't represent it. What we should actually do is detect when people try to type out 0x80000000i32 or 0x80i8, etc, and have a lint that warns about this problem. I'm thinking the lint should suggest casting to the unsigned type and back, because the user is probably trying to do bit manipulation which has subtleties with signed integers.

#53628, #99195, #108269

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.L-overflowing_literalsLint: overflowing_literalsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions