Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: https://github.com/rust-lang/rust/issues/43244 [1]
Link: https://github.com/rust-lang/rust/pull/137109 [2]
Link: https://github.com/rust-lang/rust/pull/133265 [3]
Link: https://patch.msgid.link/20260405235309.418950-16-ojeda@kernel.org
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+8 -4
+5 -4
rust/macros/kunit.rs
··· 87 87 continue; 88 88 }; 89 89 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 + { 94 95 processed_items.push(Item::Fn(f)); 95 96 continue; 96 97 }
+3
rust/macros/lib.rs
··· 6 6 // and thus add a dependency on `include/config/RUSTC_VERSION_TEXT`, which is 7 7 // touched by Kconfig when the version string from the compiler changes. 8 8 9 + // Stable since Rust 1.87.0. 10 + #![feature(extract_if)] 11 + // 9 12 // Stable since Rust 1.88.0 under a different name, `proc_macro_span_file`, 10 13 // which was added in Rust 1.88.0. This is why `cfg_attr` is used here, i.e. 11 14 // to avoid depending on the full `proc_macro_span` on Rust >= 1.88.0.