PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: bitflags/bitflags (rust)

Issue:
No `clear()` method?
~~The previous major version used to have a `clear` method (i think?), while migrating to the new version i saw that this method was not present anymore, is this expected? it feels like a common behaviour to include, currently i'm doing this~~
I used to clear the flags by doing `self.bits = 0` in the old version of the library, in the current major version i saw this seems to be a way to do it instead, is there a reason why there is not a `.clear()` method or similar that unsets all bits?
```rust
bitflags! {
    #[wasm_bindgen]
    #[derive(Serialize, Copy, Clone, Debug)]
    pub struct Flags: u16 {
        const Carry    = 1<<1;
        const Overflow = 1<<2;
        const Zero     = 1<<3;
        const Negative = 1<<4;
        const Extend   = 1<<5;
    }
}

impl Flags {
    pub fn clear(&mut self) {
        self.set(Flags::all(), false);
        //or
       *self = Flags::empty();
    }
}
```

Pull request:
`Flags` trait: add `clear(&mut self)` method
This pull request adds a method to the `Flags` trait that clears all set bits in the flags. Resolves #418.


Patch:
diff --git a/src/traits.rs b/src/traits.rs
index d351bfc..d7c4d13 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -293,6 +293,14 @@ pub trait Flags: Sized + 'static {
         }
     }
 
+    /// Unsets all bits in the flags.
+    fn clear(&mut self)
+    where
+        Self: Sized,
+    {
+        *self = Self::empty();
+    }
+
     /// The bitwise and (`&`) of the bits in two flags values.
     #[must_use]
     fn intersection(self, other: Self) -> Self {


Test patch:
diff --git a/src/tests.rs b/src/tests.rs
index 547c28d..0770e1b 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1,6 +1,7 @@
 mod all;
 mod bitflags_match;
 mod bits;
+mod clear;
 mod complement;
 mod contains;
 mod difference;
diff --git a/src/tests/clear.rs b/src/tests/clear.rs
new file mode 100644
index 0000000..2d42cce
--- /dev/null
+++ b/src/tests/clear.rs
@@ -0,0 +1,27 @@
+use super::*;
+
+use crate::Flags;
+
+#[test]
+fn cases() {
+    case(TestFlags::from_bits_retain(0));
+
+    case(TestFlags::from_bits_retain(1 << 3));
+
+    case(TestFlags::ABC | TestFlags::from_bits_retain(1 << 3));
+
+    case(TestZero::empty());
+
+    case(TestZero::all());
+
+    case(TestFlags::from_bits_retain(1 << 3) | TestFlags::all());
+}
+
+#[track_caller]
+fn case<T: Flags + std::fmt::Debug>(mut flags: T)
+where
+    T: std::fmt::Debug + PartialEq + Copy,
+{
+    flags.clear();
+    assert_eq!(flags, T::empty(), "{:?}.clear()", flags);
+}