[PATCH] rust/common: rename IntegerExt::bit() to single_bit()

Samuel Tardieu posted 1 patch 1 week, 1 day ago
rust/common/src/bitops.rs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] rust/common: rename IntegerExt::bit() to single_bit()
Posted by Samuel Tardieu 1 week, 1 day ago
An experimental Rust nightly feature `get_set_bit` introduces a `bit()`
method on integer types which checks whether a specific bit is set. This
clashes with QEMU's `IntegerExt::bit()` associated function which
returns an integer with one particular bit set.

While the `get_set_bit` feature has no planned stabilization date yet,
this is reported as a `unstable_name_collisions` warning when compiling
with the `strict_rust_lints` option, and warnings are turned into errors.
Renaming `IntegerExt::bit()` to `IntegerExt::single_bit()` prevents this.

Signed-off-by: Samuel Tardieu <sam@rfc1149.net>
---
 rust/common/src/bitops.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rust/common/src/bitops.rs b/rust/common/src/bitops.rs
index 06c78c3b8a..a0aff75d76 100644
--- a/rust/common/src/bitops.rs
+++ b/rust/common/src/bitops.rs
@@ -34,7 +34,7 @@ pub trait IntegerExt:
 
     #[inline]
     #[must_use]
-    fn bit(start: u32) -> Self
+    fn single_bit(start: u32) -> Self
     {
         debug_assert!(start < Self::BITS);
 
@@ -105,9 +105,9 @@ fn test_extract() {
     }
 
     #[test]
-    fn test_bit() {
-        assert_eq!(u8::bit(7), 128);
-        assert_eq!(u32::bit(16), 0x10000);
+    fn test_single_bit() {
+        assert_eq!(u8::single_bit(7), 128);
+        assert_eq!(u32::single_bit(16), 0x10000);
     }
 
     #[test]

---
base-commit: e9fa1f66f0d47c74b6766e1b8b87ad7c2a9394d5
change-id: 20261114-rust-single-bit-60366e5998ff

Best regards,
--  
Samuel Tardieu <sam@rfc1149.net>
Re: [PATCH] rust/common: rename IntegerExt::bit() to single_bit()
Posted by Paolo Bonzini 5 days, 14 hours ago
Queued, thanks.

Paolo
Re: [PATCH] rust/common: rename IntegerExt::bit() to single_bit()
Posted by Peter Maydell 1 week, 1 day ago
On Sat, 14 Nov 2026 at 10:02, Samuel Tardieu <sam@rfc1149.net> wrote:
>
> An experimental Rust nightly feature `get_set_bit` introduces a `bit()`
> method on integer types which checks whether a specific bit is set. This
> clashes with QEMU's `IntegerExt::bit()` associated function which
> returns an integer with one particular bit set.
>
> While the `get_set_bit` feature has no planned stabilization date yet,
> this is reported as a `unstable_name_collisions` warning when compiling
> with the `strict_rust_lints` option, and warnings are turned into errors.
> Renaming `IntegerExt::bit()` to `IntegerExt::single_bit()` prevents this.
>
> Signed-off-by: Samuel Tardieu <sam@rfc1149.net>

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4842

thanks
-- PMM