diff mbox series

[v6,18/18] rust: clippy: disallow `addr_of[_mut]!` macros

Message ID 20250418014143.888022-19-contact@antoniohickey.com (mailing list archive)
State New
Headers show
Series refactor to utilize `&raw [const|mut]` | expand

Commit Message

Antonio Hickey April 18, 2025, 1:41 a.m. UTC
With the `raw_ref_op` feature enabled we no longer want to
allow use of the `addr_of!` and `addr_of_mut!` macros.

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

Note that this lint isn't currently reliable, but we enable
it nevertheless because:
1. Document that one shouldn't use the `addr_of[_mut]!` macros.
2. When the lint becomes useful we will already have it enabled.

Suggested-by: Benno Lossin <benno.lossin@proton.me>
Link: https://github.com/Rust-for-Linux/linux/issues/1148
Link: https://github.com/rust-lang/rust-clippy/issues/11431
Signed-off-by: Antonio Hickey <contact@antoniohickey.com>
---
 .clippy.toml | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/.clippy.toml b/.clippy.toml
index 815c94732ed7..b7d87377a468 100644
--- a/.clippy.toml
+++ b/.clippy.toml
@@ -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 suggest use of `&raw const` 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 const` instead `addr_of!`" },
 ]