[PATCH] rust: fix formatting expressions

From: Tamir Duberstein
Date: Sun Jan 04 2026 - 08:00:42 EST


From: Tamir Duberstein <tamird@xxxxxxxxx>

Allow usage like `pr_info!("one + 1 = {}", one + 1)` to compile by
ensuring that a reference is taken to the entire expression.

Fixes: c5cf01ba8dfe ("rust: support formatting of foreign types")
Reported-by: Janne Grunau <j@xxxxxxxxxx>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
---
Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
---
rust/macros/fmt.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/macros/fmt.rs b/rust/macros/fmt.rs
index 2f4b9f6e2211..8354abd54502 100644
--- a/rust/macros/fmt.rs
+++ b/rust/macros/fmt.rs
@@ -67,7 +67,7 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream {
}
(None, acc)
})();
- args.extend(quote_spanned!(first_span => #lhs #adapter(&#rhs)));
+ args.extend(quote_spanned!(first_span => #lhs #adapter(&(#rhs))));
}
};


---
base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da
change-id: 20260104-fmt-paren-e92eb804a4aa

Best regards,
--
Tamir Duberstein <tamird@xxxxxxxxx>