mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
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>
This commit is contained in:
@@ -87,10 +87,11 @@ 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 {
|
||||
if f.attrs
|
||||
.extract_if(.., |attr| attr.path().is_ident("test"))
|
||||
.count()
|
||||
== 0
|
||||
{
|
||||
processed_items.push(Item::Fn(f));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
// and thus add a dependency on `include/config/RUSTC_VERSION_TEXT`, which is
|
||||
// touched by Kconfig when the version string from the compiler changes.
|
||||
|
||||
// Stable since Rust 1.87.0.
|
||||
#![feature(extract_if)]
|
||||
//
|
||||
// Stable since Rust 1.88.0 under a different name, `proc_macro_span_file`,
|
||||
// which was added in Rust 1.88.0. This is why `cfg_attr` is used here, i.e.
|
||||
// to avoid depending on the full `proc_macro_span` on Rust >= 1.88.0.
|
||||
|
||||
Reference in New Issue
Block a user