[PATCH] rust: kunit: implement test attr filtering without extract_if
From: Elsanti
Date: Wed Feb 25 2026 - 14:48:04 EST
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@xxxxxxxxx>
---
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
+ });
+ if !had_test_attr {
processed_items.push(Item::Fn(f));
continue;
}
--
2.53.0