Re: [PATCH 1/2] kbuild: rust: allow `clippy::uninlined_format_args`
From: Gary Guo
Date: Thu Apr 09 2026 - 13:07:00 EST
On Thu Apr 9, 2026 at 5:18 PM BST, Tamir Duberstein wrote:
> On Fri, Apr 3, 2026 at 9:07 AM Miguel Ojeda
> <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>>
>> On Fri, Apr 3, 2026 at 12:25 PM Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
>> >
>> > Seeing this patch a bit late but in clippy 1.85.0 there is
>> > `#[clippy::format_args]` which would permit us to make the lint work
>> > with our custom macros.
>>
>> +1, that may be good to consider, especially with the bump -- added
>> and backlinked in:
>>
>> https://github.com/Rust-for-Linux/linux/issues/349
>>
>> Maybe an issue would be good to create too.
>
> Turns out `#[clippy::format_args]` doesn't work for us due to the
> `fmt!` proc-macro.
>
> It seems the handling of `#[clippy::format_args]` is more
> sophisticated than (at least I) expected: it doesn't blindly check the
> inputs to annotated macros, but rather looks for the place where
> `fmt::Arguments` are created.
>
> In our case something like `pr_info!("{}", i)` ends up expanding to
> `core::format_args!("{}", Adapter(&(i)))`, which does not trigger
> `uninlined_format_args`.
>
> We also cannot fix that just by having `fmt!` assign `Adapter(&(i))`
> to a local variable and then return `fmt::Arguments`, since
> `core::format_args!` borrows its arguments. The local would not live
> long enough.
>
> I filed this upstream as https://github.com/rust-lang/rust-clippy/issues/16833.
The issue is that by the time Clippy lints run, it only have post-expansion
results. The pre-expansion AST is no longer available.
But if you run your lints pre-expansion, the name resolver and query engine is
not yet available (resolution of macro names happen during expansion).
This is generally tricky, the way Clippy works is it tries to reconstruct the
macro invocation from the expanded result.
Best,
Gary