All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nguyen Dinh Phi <phind.uet@gmail.com>
To: pbonzini@redhat.com, qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org, Nguyen Dinh Phi <phind.uet@gmail.com>
Subject: [PATCH 1/2] rust/bits: Align SubAssign behavior with Sub
Date: Mon,  3 Aug 2026 01:03:44 +0800	[thread overview]
Message-ID: <20260802170346.3493821-2-phind.uet@gmail.com> (raw)
In-Reply-To: <20260802170346.3493821-1-phind.uet@gmail.com>

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>
---
 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 d1141f7c88..60b63f969d 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.53.0



  reply	other threads:[~2026-08-02 17:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 17:03 [PATCH 0/2] rust/bits: Fix minor bugs in bits crate Nguyen Dinh Phi
2026-08-02 17:03 ` Nguyen Dinh Phi [this message]
2026-08-02 17:03 ` [PATCH 2/2] rust/bits: Use checked_ilog2() in Binary::format to avoid panic Nguyen Dinh Phi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260802170346.3493821-2-phind.uet@gmail.com \
    --to=phind.uet@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.