-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Negative numbers in types like-uint #5477
Comments
Probably related to #2438. |
Should this be done in |
Nominating for production-ready. |
Yeah, I agree with that nomination. |
This should really be a lint I think |
accepted for well-defined milestone |
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. |
I think we should have a lint for bare |
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. |
I think at this point we've gone whole-hog on accepting that not warning on this is a feature. Nominating for closure. |
Lints are not a language backwards-compatibility issue. Recategorizing as P-low, not 1.0 milestone. |
image-rs/image#305 is an example of a real-world bug that would have been caught by this warning. That bug involved code like |
see #23945; we're going further than a lint and moving to a feature-gate at this point. The goals are two-fold:
|
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? |
Yes, although that would be somewhat of a breaking change.
|
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...) |
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 |
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! |
The compiler should show a warning message when is used a negative number into a like-uint type
The text was updated successfully, but these errors were encountered: