rust: bitmap: clean Rust 1.92.0 `unused_unsafe` warning
Subsystems (2)
Miguel Ojeda
maintainerPATCH 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
@@ -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
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: unnecessaryunsafeblock
-->rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblock
|
= note:-D unused-unsafeimplied by-D warnings= help: to override-D warningsadd#[allow(unused_unsafe)]error: unnecessary
unsafeblock
-->rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblock
Quoted 5 lines
Thus allow both instances to clean the warning in newer compilers.
Signed-off-by Miguel Ojeda <[email protected]>
Yury Norov
reviewerQuoted 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: unnecessaryunsafeblock
-->rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblock
|
= note:-D unused-unsafeimplied by-D warnings= help: to override-D warningsadd#[allow(unused_unsafe)]error: unnecessary
unsafeblock
-->rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblock
Quoted 7 lines
Quoted 5 lines
Thus allow both instances to clean the warning in newer compilers.
Signed-off-by Miguel Ojeda <[email protected]>Reviewed-by Alice Ryhl <[email protected]>
Added in bitmap-for-next.
Thanks,
Yury
Alice Ryhl
maintainerQuoted 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: unnecessaryunsafeblock
-->rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblock
|
= note:-D unused-unsafeimplied by-D warnings= help: to override-D warningsadd#[allow(unused_unsafe)]error: unnecessary
unsafeblock
-->rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblockThus allow both instances to clean the warning in newer compilers.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Signed-off-by Miguel Ojeda <[email protected]>Reviewed-by Alice Ryhl <[email protected]>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
Yury Norov
reviewerQuoted 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: unnecessaryunsafeblock
-->rust/kernel/bitmap.rs:169:13
|
169 | unsafe { core::ptr::addr_of!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblock
|
= note:-D unused-unsafeimplied by-D warnings= help: to override-D warningsadd#[allow(unused_unsafe)]error: unnecessary
unsafeblock
-->rust/kernel/bitmap.rs:185:13
|
185 | unsafe { core::ptr::addr_of_mut!(self.repr.bitmap) }
| ^^^^^^ unnecessaryunsafeblockThus allow both instances to clean the warning in newer compilers.
Signed-off-by Miguel Ojeda <[email protected]>
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Alice Ryhl <[email protected]>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
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