From: Gary Guo <gary@garyguo.net>
To: Elsanti <santiagojoseleal27@gmail.com>
Cc: brendan.higgins@linux.dev, davidgow@google.com, ojeda@kernel.org,
raemoar63@gmail.com, boqun@kernel.org, bjorn3_gh@protonmail.com,
lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
tmgross@umich.edu, dakr@kernel.org,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: kunit: implement test attr filtering without extract_if
Date: Wed, 25 Feb 2026 21:07:56 +0000 [thread overview]
Message-ID: <bfcdcd95aff2e515401784f464c61312@garyguo.net> (raw)
In-Reply-To: <20260225194543.1542668-1-santiagojoseleal27@gmail.com>
On 2026-02-25 19:45, Elsanti wrote:
> Replace the TODO-only removal of #[test] attributes with a
> retain_mut-based filter that works with the current MSRV.
> This preserves test detection without depending on
> Vec::extract_if and keeps the generated KUnit wrappers correct.
>
> Signed-off-by: Elsanti <santiagojoseleal27@gmail.com>
> ---
> rust/macros/kunit.rs | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/rust/macros/kunit.rs b/rust/macros/kunit.rs
> index 6be880d634e2..e064419bfc10 100644
> --- a/rust/macros/kunit.rs
> +++ b/rust/macros/kunit.rs
> @@ -87,10 +87,15 @@ pub(crate) fn kunit_tests(test_suite: Ident, mut module: ItemMod) -> Result<Toke
> continue;
> };
>
> - // TODO: Replace below with `extract_if` when MSRV is bumped above 1.85.
> - let before_len = f.attrs.len();
> - f.attrs.retain(|attr| !attr.path().is_ident("test"));
> - if f.attrs.len() == before_len {
> + let mut had_test_attr = false;
> + f.attrs.retain_mut(|attr| {
> + let is_test = attr.path().is_ident("test");
> + if is_test {
> + had_test_attr = true;
> + }
> + !is_test
> + });
Eh, no. I think the current code is more readable. I added the TODO because I think
if f.attrs.extract_if(|attr| attr.path().is_ident("test")).count() == 0 {
...
}
is slightly more readable, not that I had any issue with length comparison.
Best,
Gary
> + if !had_test_attr {
> processed_items.push(Item::Fn(f));
> continue;
> }
prev parent reply other threads:[~2026-02-25 21:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 19:45 [PATCH] rust: kunit: implement test attr filtering without extract_if Elsanti
2026-02-25 21:07 ` 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=bfcdcd95aff2e515401784f464c61312@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=dakr@kernel.org \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=santiagojoseleal27@gmail.com \
--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