Skip to content
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

Handle negative literals in cast overflow warning #48535

Closed
estebank opened this issue Feb 25, 2018 · 0 comments · Fixed by #82829
Closed

Handle negative literals in cast overflow warning #48535

estebank opened this issue Feb 25, 2018 · 0 comments · Fixed by #82829
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint 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. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

#48432 introduced a warning note explaining why a given literal falls outside of the size of the expected type.

In the case of negative literals, the output can be confusing:

warning: literal out of range for i8
  --> $DIR/type-overflow.rs:34:17
   |
34 |     let fail = -0b1111_1111i8; //~WARNING literal out of range for i8
   |                 ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16`
   |
   = note: the literal `0b1111_1111i8` (decimal `255`) does not fit into an `i8` and will become `-1i8`

fail will end up with the value 1, as the binary literal evaluates to -1, but it is negated again. The warning should be extended to catch this case and either modify the existing note/label, or add an extra note explaining that the value is being affected further by the outer -, resulting in the final value 1.

@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Feb 25, 2018
@estebank estebank added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2019
@bors bors closed this as completed in 0ee2f4c Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint 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. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant