Skip to contentSkip to conversation

rust/common: rename IntegerExt::bit() to single_bit()

PATCH Applied Samuel Tardieu 3 participants 3 messages Nov 14 – Nov 17 Rust

lore
Share & tools
lore
#0 lore raw

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

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.

---
 rust/common/src/bitops.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
rust/common/src/bitops.rs +4 -4
index 06c78c3b8a..a0aff75d76 100644
@@ -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,

Signature · 1 line
Samuel Tardieu <[email protected]>
#1 lore raw
Quoted 6 lines · Samuel Tardieu

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.

Quoted 6 lines

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.

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

thanks
-- PMM