Skip to content

Commit fb7d645

Browse files
alvinsun039ojeda
authored andcommitted
rust: fmt: fix {:p} printing stack addresses
The `impl_fmt_adapter_forward!` macro forwards `Pointer` for `Adapter<T>` by destructuring `self` into a local `t`, causing `{:p}` to print the address of that temporary stack variable rather than the actual pointer. Remove `Pointer` from the macro and provide a manual impl for `Adapter<&T>` that passes `self.0` directly. Signed-off-by: Ke Sun <sunke@kylinos.cn> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Tested-by: Link Mauve <linkmauve@linkmauve.fr> Cc: stable@vger.kernel.org Fixes: c5cf01b ("rust: support formatting of foreign types") Link: https://patch.msgid.link/20260810-hashedptr-v15-1-eafd27d36476@kylinos.cn Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent a697e26 commit fb7d645

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎rust/kernel/fmt.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ use core::fmt::{
4343
UpperExp,
4444
UpperHex, //
4545
};
46-
impl_fmt_adapter_forward!(Debug, LowerHex, UpperHex, Octal, Binary, Pointer, LowerExp, UpperExp);
46+
impl_fmt_adapter_forward!(Debug, LowerHex, UpperHex, Octal, Binary, LowerExp, UpperExp);
47+
48+
impl<T: ?Sized + Pointer> Pointer for Adapter<&T> {
49+
#[inline]
50+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
51+
Pointer::fmt(self.0, f)
52+
}
53+
}
4754

4855
/// A copy of [`core::fmt::Display`] that allows us to implement it for foreign types.
4956
///

0 commit comments

Comments
 (0)