[PATCH] rust: fix formatting expressions

Tamir Duberstein posted 1 patch 1 month ago
rust/macros/fmt.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] rust: fix formatting expressions
Posted by Tamir Duberstein 1 month ago
From: Tamir Duberstein <tamird@gmail.com>

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@jannau.net>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
---
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 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@gmail.com>
Re: [PATCH] rust: fix formatting expressions
Posted by Andreas Hindborg 3 weeks, 3 days ago
"Tamir Duberstein" <tamird@kernel.org> writes:

> From: Tamir Duberstein <tamird@gmail.com>
>
> 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@jannau.net>
> Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
> ---
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>


Tested-by: Andreas Hindborg <a.hindborg@kernel.org>


Best regards,
Andreas Hindborg
Re: [PATCH] rust: fix formatting expressions
Posted by Miguel Ojeda 1 month ago
On Sun, Jan 4, 2026 at 2:00 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> From: Tamir Duberstein <tamird@gmail.com>
>
> 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@jannau.net>
> Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
> ---
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>

Applied to `rust-fixes` -- thanks everyone!

    [ Added Signed-off-by back. Reworded title. - Miguel ]

Cheers,
Miguel
Re: [PATCH] rust: fix formatting expressions
Posted by Janne Grunau 1 month ago
On Sun, Jan 04, 2026 at 08:00:27AM -0500, Tamir Duberstein wrote:
> From: Tamir Duberstein <tamird@gmail.com>
> 
> 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@jannau.net>
> Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
> ---
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> ---
>  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))));
>              }
>          };
>  

thanks, this fixes the trivial example I added to rust_minimal.rs and
all out-of-tree use in the asahi driver where I discovered the issue.

Tested-by: Janne Grunau <j@jannau.net>
Reviewed-by: Janne Grunau <j@jannau.net>

Janne
Re: [PATCH] rust: fix formatting expressions
Posted by Alice Ryhl 1 month ago
On Sun, Jan 4, 2026 at 2:00 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> From: Tamir Duberstein <tamird@gmail.com>
>
> 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@jannau.net>
> Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
> ---
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Re: [PATCH] rust: fix formatting expressions
Posted by Miguel Ojeda 1 month ago
On Sun, Jan 4, 2026 at 2:00 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
> ---
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>

Thanks Tamir, I will pick it into `rust-fixes` alongside a bunch of
other pending fixes.

Quick note in case you want to double-check your scripts: somehow you
ended up with two `---` lines and thus the SoB outside (no need to
resend).

Cheers,
Miguel
Re: [PATCH] rust: fix formatting expressions
Posted by Tamir Duberstein 1 month ago
On Sun, Jan 4, 2026 at 8:02 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Sun, Jan 4, 2026 at 2:00 PM Tamir Duberstein <tamird@kernel.org> wrote:
> >
> > Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/near/566219493
> > ---
> > Signed-off-by: Tamir Duberstein <tamird@gmail.com>
>
> Thanks Tamir, I will pick it into `rust-fixes` alongside a bunch of
> other pending fixes.
>
> Quick note in case you want to double-check your scripts: somehow you
> ended up with two `---` lines and thus the SoB outside (no need to
> resend).
>
> Cheers,
> Miguel

Ah thanks for calling out - I think I just forgot to SoB the commit
and so this came from the (empty) cover letter.

Thanks!
Tamir