Skip to content

Document behavior of bitwise operators with boolean arguments #26349

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

Merged
merged 1 commit into from
Jun 18, 2015
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
12 changes: 7 additions & 5 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2768,22 +2768,24 @@ meaning of the operators on standard types is given here.
Like the [arithmetic operators](#arithmetic-operators), bitwise operators are
syntactic sugar for calls to methods of built-in traits. This means that
bitwise operators can be overridden for user-defined types. The default
meaning of the operators on standard types is given here.
meaning of the operators on standard types is given here. Bitwise `&`, `|` and
`^` applied to boolean arguments are equivalent to logical `&&`, `||` and `!=`
evaluated in non-lazy fashion.

* `&`
: And.
: Bitwise AND.
Calls the `bitand` method of the `std::ops::BitAnd` trait.
* `|`
: Inclusive or.
: Bitwise inclusive OR.
Calls the `bitor` method of the `std::ops::BitOr` trait.
* `^`
: Exclusive or.
: Bitwise exclusive OR.
Calls the `bitxor` method of the `std::ops::BitXor` trait.
* `<<`
: Left shift.
Calls the `shl` method of the `std::ops::Shl` trait.
* `>>`
: Right shift.
: Right shift (arithmetic).
Copy link
Member

Choose a reason for hiding this comment

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

we used to have arithmetic here, but iirc, @pnkfelix suggested that we remove 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.

It was incorrectly documented as logical (here's the fix: f2e0810) but it is in fact arithmetic (#23421 (comment))

Copy link
Member

Choose a reason for hiding this comment

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

ah ha! Thanks :)

Calls the `shr` method of the `std::ops::Shr` trait.

#### Lazy boolean operators
Expand Down