You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation for BitOps -> BitOr, BitAnd and BitXor, Following documentation should be changed to use Bitwise operators for Boolean operations and not the logical operations.
// For BitOruse std::ops::BitOr;#[derive(Debug,PartialEq)]structBooleanVector(Vec<bool>);implBitOrforBooleanVector{typeOutput = Self;fnbitor(self,Self(rhs):Self) -> Self::Output{letSelf(lhs) = self;assert_eq!(lhs.len(), rhs.len());Self(lhs.iter().zip(rhs.iter()).map(|(x, y)| *x || *y).collect())// <- Here we should use bit-wise or and not logical or }}let bv1 = BooleanVector(vec![true, true, false, false]);let bv2 = BooleanVector(vec![true, false, true, false]);let expected = BooleanVector(vec![true, true, true, false]);assert_eq!(bv1 | bv2, expected);
Also, similar changes are required for Bitwise And and Bitwise Xor. Note: While the output is not wrong per se, it's actually a bit confusing since, those operators already exist for scalar versions of bool.
gabhijit
changed the title
Trivial documentation issue with core::ops::Bit{And|Or|Xor|
Trivial documentation issue with core::ops::Bit{And|Or|Xor}Nov 1, 2020
gabhijit
added a commit
to gabhijit/rust
that referenced
this issue
Nov 1, 2020
Added fixes to documentation of `BitAnd`, `BitOr`, `BitXor` and
`BitAndAssign`, where the documentation for implementation on
`Vector<bool>` was using logical operators in place of the bitwise
operators.
r? @steveklabnik
cc rust-lang#78619
Trivial fixes to bitwise operator documentation
Added fixes to documentation of `BitAnd`, `BitOr`, `BitXor` and
`BitAndAssign`, where the documentation for implementation on
`Vector<bool>` was using logical operators in place of the bitwise
operators.
r? @steveklabnik
cc rust-lang#78619
jyn514
added
the
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
label
Nov 1, 2020
This is a documentation issue.
In the documentation for BitOps ->
BitOr
,BitAnd
andBitXor
, Following documentation should be changed to use Bitwise operators for Boolean operations and not the logical operations.Also, similar changes are required for Bitwise And and Bitwise Xor. Note: While the output is not wrong per se, it's actually a bit confusing since, those operators already exist for scalar versions of
bool
.The changes for
BitXor
are more confusingWhere a simple bitwise xor above like
.map(|(x, y)| (*x ^ *y))
should suffice.I have quickly verified these changes indeed work on playground using
nightly
andstable
.Meta
Since this is really a documentation issue, added for completeness.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: