@samitouri / QOSamiQemu / commits / c5974346d7

rust/bits: Align SubAssign behavior with Sub

Update SubAssign to perform a bit-clear operation instead of arithmetic subtraction, matching the behavior of Sub. Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com> Link: https://lore.kernel.org/r/20260802170346.3493821-2-phind.uet@gmail.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Nguyen Dinh Phi committed Aug 3, 2026 at 01:03 UTC c5974346d7a7300f5350ccf7af8d61996d9bda6a
1 file changed +8 -1
rust/bits/src/lib.rs
+8 -1
@@ -320,7 +320,7 @@ macro_rules! bits {
320
321 impl ::std::ops::SubAssign<$struct_name> for $struct_name {
322 fn sub_assign(&mut self, rhs: $struct_name) {
323 - self.0 = self.0 - rhs.0
323 + self.0 &= !rhs.0
324 }
325 }
326
@@ -443,4 +443,11 @@ mod test {
443 InterruptMask::OE | InterruptMask::PE | InterruptMask::FE
444 );
445 }
446 +
447 + #[test]
448 + pub fn test_sub_assign() {
449 + let mut op1 = InterruptMask::E;
450 + op1 -= InterruptMask::RI;
451 + assert_eq!(op1, InterruptMask::E - InterruptMask::RI);
452 + }
453 }