Skip to contentSkip to conversation

rust: clippy: disable `addr_of!` and `addr_of_mut` macros

PATCH Benno Lossin 1 participant 1 message Mar 13, 2025 Rust

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Antonio Hickey

With the raw_ref_op feature enabled we no longer want to allow use of addr_of! and addr_of_mut! macros.

We instead want to use &raw and &raw mut to get raw pointers to a place.

This patch needs to be done after changing all occurrences of addr_of[_mut]!, ie the next one (otherwise it would warn about them).

I also noticed that this feature sadly doesn't work very well, see

    https://rust-for-linux.zulipchat.com/#narrow/channel/291565-Help/topic/.2Eclippy.2Etoml.20has.20no.20effect

and

    https://github.com/rust-lang/rust-clippy/issues/11431

---
Cheers,
Benno

Quoted 17 lines
---
 .clippy.toml | 4 ++++
 1 file changed, 4 insertions(+)
.clippy.toml +4 -0
index 815c94732ed7..95c73959f039 100644
@@ -8,4 +8,8 @@ disallowed-macros = [
     # The `clippy::dbg_macro` lint only works with `std::dbg!`, thus we simulate
     # it here, see: https://github.com/rust-lang/rust-clippy/issues/11303.
     { path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool" },
+    # With `raw_ref_op` feature enabled we no longer want to allow use of `addr_of!`
+    # and `addr_of_mut!` macros, but instead use `&raw` or `&raw mut`.
+    { path = "core::ptr::addr_of_mut", reason = "use `&raw mut` instead `addr_of_mut!`" },
+    { path = "core::ptr::addr_of", reason = "use `&raw` instead `addr_of!`" },
 ]