Re: [PATCH v9] rust: add new macro for common bitflag operations

From: Filipe Xavier

Date: Fri Jan 30 2026 - 04:38:46 EST


On 1/30/26 2:25 AM, Miguel Ojeda wrote:

On Sat, Jan 17, 2026 at 11:41 AM Filipe Xavier <felipeaggger@xxxxxxxxx> wrote:
We have seen a proliferation of mod_whatever::foo::Flags
being defined with essentially the same implementation
for BitAnd, BitOr, contains and etc.

This macro aims to bring a solution for this,
allowing to generate these methods for user-defined structs.
With some use cases in KMS and upcoming GPU drivers.

Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/We.20really.20need.20a.20common.20.60Flags.60.20type
Suggested-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
Suggested-by: Lyude Paul <lyude@xxxxxxxxxx>
Reviewed-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
Reviewed-by: Lyude Paul <lyude@xxxxxxxxxx>
Tested-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
Signed-off-by: Filipe Xavier <felipeaggger@xxxxxxxxx>
So I was about to apply this one and I noticed a few bits (no need for
a new version):

- This was added to the prelude -- I asked the team and they felt it
wasn't needed, so I will remove it. We can always add it later on if
needed.
Sounds good, no problem.

- Is `BitXorAssign<$flag> for $flags` missing for some reason? I will add:

impl ::core::ops::BitXorAssign<$flag> for $flags {
#[inline]
fn bitxor_assign(&mut self, rhs: $flag) {
*self = *self ^ rhs;
}
}

This is why I like to have tests for every operator... I may open
a good first issue about it :)

Regarding |BitXorAssign|, that was indeed an oversight on my part. Adding it makes perfect sense.

I also fixed an intra-doc link and tweaked a couple other bits.

Thanks for the review and for taking the time with this.

Xavier

Cheers,
Miguel