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

rewrite checked_{div,rem} to no contain any reference to panics #37029

Merged
merged 1 commit into from
Oct 8, 2016

Conversation

japaric
Copy link
Member

@japaric japaric commented Oct 7, 2016

even without optimizations

r? @alexcrichton

@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 @alexcrichton (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. Due to 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 the contribution instructions for more information.

@alexcrichton
Copy link
Member

@bors: r+ c66ae29

@japaric
Copy link
Member Author

japaric commented Oct 7, 2016

While implementing this. I noticed that overflowing_neg and checked_neg also have this problem, they directly use -self, but there's no unchecked_neg intrinsic to replace that with.

@alexcrichton
Copy link
Member

Hm I don't think -foo suffers the same problems, the compiler doesn't emit a call to panic if that overflows because it can't be UB. (in LLVM I think it's UB to divide by zero, so the panic is necessary for safety)

@japaric
Copy link
Member Author

japaric commented Oct 7, 2016

@alexcrichton Oh, that makes sense.

None
} else {
let (a, b) = self.overflowing_div(other);
if b {None} else {Some(a)}
Some(unsafe { intrinsics::unchecked_div(self, other) })
Copy link
Member

@nagisa nagisa Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why intrinsic, not wrapping_div?

EDIT: wrapping_div also has references to panic. I was thinking it used unchecked_div o.O.

Manishearth added a commit to Manishearth/rust that referenced this pull request Oct 8, 2016
…=alexcrichton

rewrite checked_{div,rem} to no contain any reference to panics

even without optimizations

r? @alexcrichton
bors added a commit that referenced this pull request Oct 8, 2016
Rollup of 6 pull requests

- Successful merges: #36937, #37016, #37028, #37029, #37031, #37034
- Failed merges: #37027
@bors bors merged commit c66ae29 into rust-lang:master Oct 8, 2016
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.

5 participants