public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Tamir Duberstein" <tamird@kernel.org>,
	"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Luis Chamberlain" <mcgrof@kernel.org>,
	"Petr Pavlu" <petr.pavlu@suse.com>,
	"Daniel Gomez" <da.gomez@kernel.org>,
	"Sami Tolvanen" <samitolvanen@google.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	rust-for-linux@vger.kernel.org,
	"Aaron Tomlin" <atomlin@atomlin.com>,
	linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kbuild@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] kbuild: rust: allow `clippy::uninlined_format_args`
Date: Thu, 09 Apr 2026 18:06:30 +0100	[thread overview]
Message-ID: <DHOSE8ZNA27J.J412X7HM45OM@garyguo.net> (raw)
In-Reply-To: <CAJ-ks9nMA1zqGhHhOk8hmfNgoODQ+D-WforPU6iCciYbPsDD-Q@mail.gmail.com>

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@gmail.com> wrote:
>>
>> On Fri, Apr 3, 2026 at 12:25 PM Tamir Duberstein <tamird@kernel.org> 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

      reply	other threads:[~2026-04-09 17:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 20:58 [PATCH 1/2] kbuild: rust: allow `clippy::uninlined_format_args` Miguel Ojeda
2026-03-31 20:58 ` [PATCH 2/2] rust: macros: simplify `format!` arguments Miguel Ojeda
2026-03-31 21:07   ` Gary Guo
2026-04-03  4:53   ` Miguel Ojeda
2026-04-03 15:52     ` Sami Tolvanen
2026-04-03 21:23       ` Miguel Ojeda
2026-03-31 21:07 ` [PATCH 1/2] kbuild: rust: allow `clippy::uninlined_format_args` Gary Guo
2026-03-31 21:14   ` Miguel Ojeda
2026-03-31 21:43     ` Gary Guo
2026-03-31 21:53       ` Miguel Ojeda
2026-04-01 15:36         ` Gary Guo
2026-04-03 10:06 ` Miguel Ojeda
2026-04-03 10:24 ` Tamir Duberstein
2026-04-03 13:07   ` Miguel Ojeda
2026-04-09 16:18     ` Tamir Duberstein
2026-04-09 17:06       ` Gary Guo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DHOSE8ZNA27J.J412X7HM45OM@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=atomlin@atomlin.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=da.gomez@kernel.org \
    --cc=dakr@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=samitolvanen@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox