Skip to contentSkip to conversation

rust: bitmap: clean Rust 1.92.0 `unused_unsafe` warning

PATCH In review Miguel Ojeda 4 participants 6 messages Oct 13, 2025 – Oct 14, 2025

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: bitmap: clean Rust 1.92.0 `unused_unsafe` warning

Starting with Rust 1.92.0 (expected 2025-12-11), Rust allows to safely take the address of a union field [1][2]:

CLIPPY L rust/kernel.o
error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block
|
= note: -D unused-unsafe implied by -D warnings = help: to override -D warnings add #[allow(unused_unsafe)]

error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block

Thus allow both instances to clean the warning in newer compilers.

---
 rust/kernel/bitmap.rs | 2 ++
 1 file changed, 2 insertions(+)
rust/kernel/bitmap.rs +2 -0
index f45915694454..711b8368b38f 100644
@@ -166,6 +166,7 @@ impl core::ops::Deref for BitmapVec {
     fn deref(&self) -> &Bitmap {
         let ptr = if self.nbits <= BITS_PER_LONG {
             // SAFETY: Bitmap is represented inline.
+            #[allow(unused_unsafe, reason = "Safe since Rust 1.92.0")]
             unsafe { core::ptr::addr_of!(self.repr.bitmap) }
         } else {
             // SAFETY: Bitmap is represented as array of `unsigned long`.
@@ -182,6 +183,7 @@ impl core::ops::DerefMut for BitmapVec {
     fn deref_mut(&mut self) -> &mut Bitmap {
         let ptr = if self.nbits <= BITS_PER_LONG {
             // SAFETY: Bitmap is represented inline.
+            #[allow(unused_unsafe, reason = "Safe since Rust 1.92.0")]
             unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
         } else {
             // SAFETY: Bitmap is represented as array of `unsigned long`.

base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787

Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Miguel Ojeda

Starting with Rust 1.92.0 (expected 2025-12-11), Rust allows to safely take the address of a union field [1][2]:

CLIPPY L rust/kernel.o
error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block
|
= note: -D unused-unsafe implied by -D warnings = help: to override -D warnings add #[allow(unused_unsafe)]

error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block

Quoted 5 lines

Thus allow both instances to clean the warning in newer compilers.

reviewer
#2 lore raw
Quoted 20 lines · Alice Ryhl
Quoted 19 lines · Miguel Ojeda

Starting with Rust 1.92.0 (expected 2025-12-11), Rust allows to safely take the address of a union field [1][2]:

CLIPPY L rust/kernel.o
error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block
|
= note: -D unused-unsafe implied by -D warnings = help: to override -D warnings add #[allow(unused_unsafe)]

error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block

Quoted 7 lines
Quoted 5 lines

Thus allow both instances to clean the warning in newer compilers.

Added in bitmap-for-next.

Thanks,
Yury

maintainer
#3 lore raw
Quoted 23 lines · Yury Norov
Quoted 22 lines · Alice Ryhl
Quoted 21 lines · Miguel Ojeda

Starting with Rust 1.92.0 (expected 2025-12-11), Rust allows to safely take the address of a union field [1][2]:

CLIPPY L rust/kernel.o
error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block
|
= note: -D unused-unsafe implied by -D warnings = help: to override -D warnings add #[allow(unused_unsafe)]

error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block

Thus allow both instances to clean the warning in newer compilers.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Added in bitmap-for-next.

Is there any possibility of landing this for an -rc of 6.18 instead of for 6.19-rc1? That way, the warning won't be present when compiling 6.18 with rustc 1.92.0 and newer.

Alice

reviewer
#4 lore raw
Quoted 28 lines · Alice Ryhl
Quoted 27 lines · Yury Norov
Quoted 26 lines · Alice Ryhl
Quoted 24 lines · Miguel Ojeda

Starting with Rust 1.92.0 (expected 2025-12-11), Rust allows to safely take the address of a union field [1][2]:

CLIPPY L rust/kernel.o
error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block
|
= note: -D unused-unsafe implied by -D warnings = help: to override -D warnings add #[allow(unused_unsafe)]

error: unnecessary unsafe block
--> rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessary unsafe block

Thus allow both instances to clean the warning in newer compilers.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Added in bitmap-for-next.

Is there any possibility of landing this for an -rc of 6.18 instead of for 6.19-rc1? That way, the warning won't be present when compiling 6.18 with rustc 1.92.0 and newer.

OK, will do -rc1

#5 lore raw
Quoted 2 lines · Yury Norov

OK, will do -rc1

Thanks Yury!

Yeah, these should generally be sent as "fixes" to Linus; otherwise we will have red CIs.

(I don't add the Fixes tag for this sort of change because the original code is fine).

Cheers,
Miguel