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

Document BinOp::is_checkable #109058

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,9 @@ impl BorrowKind {
}

impl BinOp {
/// The checkable operators are those whose overflow checking behavior is controlled by
/// -Coverflow-checks option. The remaining operators have either no overflow conditions (e.g.,
/// BitAnd, BitOr, BitXor) or are always checked for overflow (e.g., Div, Rem).
Copy link
Member

Choose a reason for hiding this comment

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

UnOp does not have is_checkable. Given these docs, that seems surprising? Neg behaves like the 'checkable' bin ops, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UnOp::Neg would be checkable. What do you find surprising about that in context of this documentation?

Copy link
Member

Choose a reason for hiding this comment

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

The surprising part is that there is no such function on UnOp -- that indicates some asymmetry in how UnOp vs BinOp are handled.

Should we also have this on UnOp, and then replace the existing direct matching on Neg that I assume is happening with an is_checkable call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Negation has a dedicated assertion kind for it, so there is no need for UnOp::is_checkable (see git grep -C20 is_checkable).

Copy link
Member

Choose a reason for hiding this comment

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

What does this have to do with assertion kinds? I was thinking of MIR building.

Though with #108282, MIR building does not use this function any more anyway. Then it's only the codegen backends and yeah there it has to do with assertion kinds.

pub fn is_checkable(self) -> bool {
use self::BinOp::*;
matches!(self, Add | Sub | Mul | Shl | Shr)
Expand Down