Skip to content

Commit b15545e

Browse files
committed
rust: macros: simplify code using feature(extract_if)
`feature(extract_if)` [1] was stabilized in Rust 1.87.0 [2], and the last significant change happened in Rust 1.85.0 [3] when the range parameter was added. That is, with our new minimum version, we can start using the feature. Thus simplify the code using the feature and remove the TODO comment. Suggested-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/rust-for-linux/DHHVSX66206Y.3E7I9QUNTCJ8I@garyguo.net/ Link: rust-lang/rust#43244 [1] Link: rust-lang/rust#137109 [2] Link: rust-lang/rust#133265 [3] Link: https://patch.msgid.link/20260405235309.418950-16-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent f2704f1 commit b15545e

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

rust/macros/kunit.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ pub(crate) fn kunit_tests(test_suite: Ident, mut module: ItemMod) -> Result<Toke
8787
continue;
8888
};
8989

90-
// TODO: Replace below with `extract_if` when MSRV is bumped above 1.85.
91-
let before_len = f.attrs.len();
92-
f.attrs.retain(|attr| !attr.path().is_ident("test"));
93-
if f.attrs.len() == before_len {
90+
if f.attrs
91+
.extract_if(.., |attr| attr.path().is_ident("test"))
92+
.count()
93+
== 0
94+
{
9495
processed_items.push(Item::Fn(f));
9596
continue;
9697
}

rust/macros/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// and thus add a dependency on `include/config/RUSTC_VERSION_TEXT`, which is
77
// touched by Kconfig when the version string from the compiler changes.
88

9+
// Stable since Rust 1.87.0.
10+
#![feature(extract_if)]
11+
//
912
// Stable since Rust 1.88.0 under a different name, `proc_macro_span_file`,
1013
// which was added in Rust 1.88.0. This is why `cfg_attr` is used here, i.e.
1114
// to avoid depending on the full `proc_macro_span` on Rust >= 1.88.0.

0 commit comments

Comments
 (0)