Skip to content

Commit 3afc385

Browse files
committed
Rollup merge of #26349 - petrochenkov:bitwise, r=steveklabnik
I'm surprised that bitwise operators `&`, `|` and `^` are implemented for `bool` arguments, because inspection of boolean's bits is not something that should be encouraged and because `&&` -> `&` is a common typo, but if they are implemented, then their behavior should be documented.
2 parents b5f2b09 + a8f666f commit 3afc385

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/doc/reference.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -2779,22 +2779,24 @@ meaning of the operators on standard types is given here.
27792779
Like the [arithmetic operators](#arithmetic-operators), bitwise operators are
27802780
syntactic sugar for calls to methods of built-in traits. This means that
27812781
bitwise operators can be overridden for user-defined types. The default
2782-
meaning of the operators on standard types is given here.
2782+
meaning of the operators on standard types is given here. Bitwise `&`, `|` and
2783+
`^` applied to boolean arguments are equivalent to logical `&&`, `||` and `!=`
2784+
evaluated in non-lazy fashion.
27832785

27842786
* `&`
2785-
: And.
2787+
: Bitwise AND.
27862788
Calls the `bitand` method of the `std::ops::BitAnd` trait.
27872789
* `|`
2788-
: Inclusive or.
2790+
: Bitwise inclusive OR.
27892791
Calls the `bitor` method of the `std::ops::BitOr` trait.
27902792
* `^`
2791-
: Exclusive or.
2793+
: Bitwise exclusive OR.
27922794
Calls the `bitxor` method of the `std::ops::BitXor` trait.
27932795
* `<<`
27942796
: Left shift.
27952797
Calls the `shl` method of the `std::ops::Shl` trait.
27962798
* `>>`
2797-
: Right shift.
2799+
: Right shift (arithmetic).
27982800
Calls the `shr` method of the `std::ops::Shr` trait.
27992801

28002802
#### Lazy boolean operators

0 commit comments

Comments
 (0)