-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic in lint for out of range literals
- Loading branch information
1 parent
6d718f2
commit 7b1916d
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7b1916d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following @pnkfelix advice to use blame rather than opening a new issue if a patch causes an undesirable change, hopefully I've done this correctly... if not, I apologize in advance.
Patch 7b1916d introduces a regression in behavior in the sense that invalid literal i64 values < -9223372036854775808i64 are no longer being properly reported as #[warn(overflowing_literals)]. The other literal checks seem to still be working.
I have been watching and thinking a lot about these few lines of code over the last few days as they have gone through various stages of being broken/fixed following the change to
abs()
which causes panic for i32::MIN & friends... mostly because I was experienced the same build-time panic/crash that patch 7b1916d fixes.As a more stable and future-proof solution I would like to propose:
The expression
(negative && v > max as u64 + 1)
relies on the fact that algebraically speaking-min == max + 1
to avoid negation and removing the need formin
completely. So hopefully it is more intuitive as well.If i128 or i256 are ever added, it should also work for these types without requiring a change to
min != i64::MIN &&
also simplifying maintenance.Is this a worthwhile change? Or am I just wasting my time investigating stuff that doesn't matter again?
Should I submit this as a "real" issue? Or is it good enough to report this via blame (which I haven't tried before)?
Here is some test code:
Results with nightly 2015-05-19:
Results with master and rustc-nightly 2015-05-24 (both after 7b1916d):
Notice the missing
invalid_literals.rs:6:22: 6:44 warning: literal out of range for i64, #[warn(overflowing_literals)]
warning for -9223372036854775809i64.Here is the patch to fix:
Final results after applying proposed patch to nightly 2015-05-24:
Is there a way to contribute test cases for compiler lint checks to help detect regressions? If so, point me in the right direction and I'll try to contribute some.
cc @alexcrichton @pnkfelix
7b1916d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely, it's a mistake (sorry for introducing it).
Fell free to open a pull request with your fix and test.
To test the issue you can add a new file with your test code (a bit simplified + deny the warning):
to the directory src/test/compile-fail and specify the expected warning messages as described here: https://github.com/rust-lang/rust-wiki-backup/blob/master/Note-testsuite.md#specifying-the-expected-errors-and-warnings
7b1916d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. You fixed the panic which was blocking me too.
Thanks for the feedback and advice. I discovered there was already a module providing tests for overflowing_literals but it was missing a couple of test cases for negative i64's out of range.
I am ready to create the pull request, and all tests are passing.
Would it be best to request you as the reviewer or possibly @alexcrichton or @pnkfelix since they have been involved in the discussions surrounding
abs()
changes and panic behavior? Or just let bors pick someone at random to review? This is my first time contributing to rust, so I wasn't sure how this works.7b1916d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no rights to approve pull requests and Alex is on vacation, so @pnkfelix or random would be a better choice.