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 upstd: Make abs() panic on overflow in debug mode #25441
Conversation
rust-highfive
assigned
brson
May 15, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
referenced this pull request
May 15, 2015
Closed
std::i32::MIN.abs() results in panicked at 'arithmetic operation overflowed' #25378
This comment has been minimized.
This comment has been minimized.
|
r? @aturon |
rust-highfive
assigned
aturon
and unassigned
brson
May 15, 2015
aturon
reviewed
May 18, 2015
src/libcore/num/mod.rs
Outdated
| @@ -569,7 +569,7 @@ macro_rules! int_impl { | |||
| #[inline] | |||
| pub fn abs(self) -> $T { | |||
| if self.is_negative() { | |||
| self.wrapping_neg() | |||
| -self | |||
This comment has been minimized.
This comment has been minimized.
aturon
May 18, 2015
Member
Can you leave a comment saying that this has the correct overflow semantics only if kept as inline given how std is distributed? I hope we can do something more robust in the future.
Otherwise r=me.
alexcrichton
force-pushed the
alexcrichton:debug-panic-neg
branch
from
2a05f77
to
5f39ceb
May 19, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
May 19, 2015
This comment has been minimized.
This comment has been minimized.
bors
merged commit 5f39ceb
into
rust-lang:master
May 19, 2015
alexcrichton
added
beta-nominated
T-libs
labels
May 19, 2015
alexcrichton
deleted the
alexcrichton:debug-panic-neg
branch
May 19, 2015
alexcrichton
restored the
alexcrichton:debug-panic-neg
branch
May 19, 2015
alexcrichton
deleted the
alexcrichton:debug-panic-neg
branch
May 19, 2015
alexcrichton
restored the
alexcrichton:debug-panic-neg
branch
May 19, 2015
alexcrichton
deleted the
alexcrichton:debug-panic-neg
branch
May 19, 2015
This comment has been minimized.
This comment has been minimized.
|
Hey, it broke the compiler
|
petrochenkov
referenced this pull request
May 19, 2015
Merged
Fix panic in lint for out of range literals #25612
bors
added a commit
that referenced
this pull request
May 21, 2015
alexcrichton
added
the
beta-accepted
label
Jun 9, 2015
This comment has been minimized.
This comment has been minimized.
|
Accepting for a beta backport |
alexcrichton
removed
the
beta-nominated
label
Jun 11, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
alexcrichton commentedMay 15, 2015
Debug overflow checks for arithmetic negation landed in #24500, at which time
the
absmethod on signed integers was changed to usingwrapping_negtoensure that the function never panicked. This implied that
absofINT_MINwould return
INT_MIN, another negative value. When this change was back-portedto beta, however, in #24708, the
wrapping_negfunction had not yet beenbackported, so the implementation was changed in #24785 to
!self + 1. Thischange had the unintended side effect of enabling debug overflow checks for the
absfunction. Consequently, the current state of affairs is that the betabranch checks for overflow in debug mode for
absand the nightly branch doesnot.
This commit alters the behavior of nightly to have
absalways check foroverflow in debug mode. This change is more consistent with the way the standard
library treats overflow as well, and it is also not a breaking change as it's
what the beta branch currently does (albeit if by accident).
cc #25378