Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNegative numbers in types like-uint #5477
Comments
This comment has been minimized.
This comment has been minimized.
|
Probably related to #2438. |
This comment has been minimized.
This comment has been minimized.
|
Should this be done in |
This comment has been minimized.
This comment has been minimized.
|
Nominating for production-ready. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I agree with that nomination. |
This comment has been minimized.
This comment has been minimized.
|
This should really be a lint I think |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
accepted for well-defined milestone |
This comment has been minimized.
This comment has been minimized.
|
Nominating because I believe we decided to not do this for negative numbers and the warning is already implemented for positive numbers. I think this can be closed. |
This comment has been minimized.
This comment has been minimized.
|
I think we should have a lint for bare |
This comment has been minimized.
This comment has been minimized.
|
Could this lint be combined with the type_overflow lint? The message of that lint ("literal out of range for its type") would fit in my opinion and and it shouldn't be too hard to extend the code of this lint. |
thestinger
referenced this issue
May 7, 2014
Closed
Decrementing range behaviour is very confusing when used with unsigned integers #14020
hirschenberger
referenced this issue
May 23, 2014
Closed
Missing some warnings about "literal out of range for its type" #14165
This comment has been minimized.
This comment has been minimized.
|
I think at this point we've gone whole-hog on accepting that not warning on this is a feature. Nominating for closure. |
cmr
added
the
I-nominated
label
Jul 3, 2014
This comment has been minimized.
This comment has been minimized.
|
Lints are not a language backwards-compatibility issue. Recategorizing as P-low, not 1.0 milestone. |
pnkfelix
added
P-low
and removed
P-backcompat-lang
labels
Jul 3, 2014
alexcrichton
removed
the
I-nominated
label
Jul 3, 2014
Gankro
referenced this issue
Jul 23, 2014
Closed
Fixed length array type with negative count is accepted #15917
This was referenced Aug 7, 2014
killercup
referenced this issue
Aug 19, 2014
Closed
Array length is not bigger than a negative number #16605
huonw
referenced this issue
Jan 13, 2015
Closed
Negation of unsigned literals lint does not fire when literal type is deduced #16445
steveklabnik
referenced this issue
Jan 27, 2015
Closed
Add a warning for casts with loss of precision #17900
This comment has been minimized.
This comment has been minimized.
|
PistonDevelopers/image#305 is an example of a real-world bug that would have been caught by this warning. That bug involved code like |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
see #23945; we're going further than a lint and moving to a feature-gate at this point. The goals are two-fold:
|
This comment has been minimized.
This comment has been minimized.
|
Code like this compiles and runs without error in stable rustc today: let a = -1; // 'a' gets inferred to u32, but the code compiles without error
let b: u32 = a;Is the intention to stop that code from compiling or issue a runtime error? |
This comment has been minimized.
This comment has been minimized.
|
Yes, although that would be somewhat of a breaking change.
|
This comment has been minimized.
This comment has been minimized.
|
The intention was to force examples like above comment to be feature-gated (and thus you'd have to opt-in to be able to write them). But it seems like the feature-gating code in #23945 did not catch this case (or it has regressed since then, which seems less likely to me...) |
This comment has been minimized.
This comment has been minimized.
let a = -1; // 'a' gets inferred to u32, but the code compiles without error
let b: u32 = a;Gives a warning in stable and fails to compile in nightly for me on play.rust-lang.org |
This comment has been minimized.
This comment has been minimized.
|
Yes, I would consider this fixed. The example is now fixed, it's behind a feature gate, and so when/if the gate is stabilized or removed, this will end up being discussed, so I think all of the concerns in this ticket are taken care of. Let me know if that's wrong! |
tredoe commentedMar 21, 2013
The compiler should show a warning message when is used a negative number into a like-uint type