Special case overflowing literal lints to warn about -iX::MIN
#108383
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
L-overflowing_literals
Lint: overflowing_literals
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I just found several issues where people forget that
-i32::MAX != i32::MIN
,i32::MAX == 7fffffff
whilei32::MIN == -0x80000000
. People see that-0x80000000
works and then mistakenly try to use+0x80000000
which doesn't work becausei32
can't represent it. What we should actually do is detect when people try to type out0x80000000i32
or0x80i8
, 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
The text was updated successfully, but these errors were encountered: