From: Nguyen Dinh Phi <[email protected]> Update SubAssign to perform a bit-clear operation instead of arithmetic subtraction, matching the behavior of Sub.
Signed-off-by: Nguyen Dinh Phi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]> --- rust/bits/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/bits/src/lib.rs b/rust/bits/src/lib.rs index d1141f7c882..60b63f969dc 100644 --- a/rust/bits/src/lib.rs +++ b/rust/bits/src/lib.rs @@ -320,7 +320,7 @@ fn sub(self, rhs: $struct_name) -> Self::Output { impl ::std::ops::SubAssign<$struct_name> for $struct_name { fn sub_assign(&mut self, rhs: $struct_name) { - self.0 = self.0 - rhs.0 + self.0 &= !rhs.0 } } @@ -443,4 +443,11 @@ pub fn test_xor() { InterruptMask::OE | InterruptMask::PE | InterruptMask::FE ); } + + #[test] + pub fn test_sub_assign() { + let mut op1 = InterruptMask::E; + op1 -= InterruptMask::RI; + assert_eq!(op1, InterruptMask::E - InterruptMask::RI); + } } -- 2.55.0
