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

- Fix regression of literal out of range check for negative i64 value #25778

Merged
merged 1 commit into from
May 26, 2015

Conversation

econoplas
Copy link
Contributor

A regression was introduced by commit 7b1916d #25612. Negative signed integer literals less than -9223372036854775808i64 were no longer properly reported as #[warn(overflowing_literals)].

Also adding missing test cases to test/compile-fail/lint-type-overflow.rs which could have detected the regression.

Further explanation:

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 for min completely.

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.

r? @pnkfelix

…s which was introduced by commit 7b1916d.

- Add missing test cases to test/compile-fail/lint-type-overflow.rs which would have detected the regression.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@pnkfelix
Copy link
Member

If i128 or i256 are ever added, it should also work for these types without requiring a change to min != i64::MIN

I don't think this is really true, but that quibble is not going to block this PR. (The max as u64 + 1 would overflow with those types, causing a debug build of rustc to ICE)

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 26, 2015

📌 Commit 43502ad has been approved by pnkfelix

@bors
Copy link
Contributor

bors commented May 26, 2015

⌛ Testing commit 43502ad with merge 8a87294...

bors added a commit that referenced this pull request May 26, 2015
A regression was introduced by commit 7b1916d #25612.  Negative signed integer literals less than -9223372036854775808i64 were no longer properly reported as #[warn(overflowing_literals)].

Also adding missing test cases to test/compile-fail/lint-type-overflow.rs which could have detected the regression.

Further explanation:

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 for `min` completely.

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.

r? @pnkfelix
@bors bors merged commit 43502ad into rust-lang:master May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants