rust: cpufreq: clean new `clippy::map_or_identity` lint for Rust 1.98.0
Subsystems (3)
Miguel Ojeda
maintainerPATCH 1/1 rust: cpufreq: clean new `clippy::map_or_identity` lint for Rust 1.98.0
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint clippy::map_or_identity [1][2], which currently triggers in a single case:
warning: expression can be simplified using `Result::unwrap_or()`
--> rust/kernel/cpufreq.rs:1326:60
|
1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity
= note: `-W clippy::map-or-identity` implied by `-W clippy::all`
= help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]`
help: consider using `unwrap_or`
|
1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f))
1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0))
|The suggestion is valid, thus clean it up.
--- rust/kernel/cpufreq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/cpufreq.rs +1 -1
@@ -1323,7 +1323,7 @@ impl<T: Driver> Registration<T> {// SAFETY: The C API guarantees that `cpu` refers to a valid CPU number. let cpu_id =unsafe {CpuId ::from_u32_unchecked (cpu) }; -PolicyCpu ::from_cpu (cpu_id).map_or (0 , |mut policy|T ::get (&mut policy).map_or (0 , |f| f)) +PolicyCpu ::from_cpu (cpu_id).map_or (0 , |mut policy|T ::get (&mut policy).unwrap_or (0 )) }/// Driver's `update_limit` callback.
base-commit: 420dd187e1572bb7e232781bc4377a80c8eb64fb
Signature · 1 line
2.54.0
Quoted 19 lines · Miguel Ojeda
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint
clippy::map_or_identity[1][2], which currently triggers in a single case:warning: expression can be simplified using `Result::unwrap_or()` --> rust/kernel/cpufreq.rs:1326:60 | 1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity = note: `-W clippy::map-or-identity` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]` help: consider using `unwrap_or` | 1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) 1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0)) |
Quoted 6 lines
The suggestion is valid, thus clean it up.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Quoted 19 lines · Miguel Ojeda
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint
clippy::map_or_identity[1][2], which currently triggers in a single case:warning: expression can be simplified using `Result::unwrap_or()` --> rust/kernel/cpufreq.rs:1326:60 | 1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity = note: `-W clippy::map-or-identity` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]` help: consider using `unwrap_or` | 1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) 1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0)) |
Quoted 6 lines
The suggestion is valid, thus clean it up.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Quoted 3 lines
--- rust/kernel/cpufreq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 20 lines · Miguel Ojeda
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint
clippy::map_or_identity[1][2], which currently triggers in a single case:warning: expression can be simplified using `Result::unwrap_or()` --> rust/kernel/cpufreq.rs:1326:60 | 1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity = note: `-W clippy::map-or-identity` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]` help: consider using `unwrap_or` | 1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) 1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0)) |
Quoted 6 lines
The suggestion is valid, thus clean it up.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Viresh, Rafael: I can put this into rust-next if you prefer (I considered rust-fixes, but it is not important enough at this stage).
Cheers,
Miguel
Quoted 23 lines · Miguel Ojeda
Quoted 22 lines · Miguel Ojeda
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint
clippy::map_or_identity[1][2], which currently triggers in a single case:warning: expression can be simplified using `Result::unwrap_or()` --> rust/kernel/cpufreq.rs:1326:60 | 1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity = note: `-W clippy::map-or-identity` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]` help: consider using `unwrap_or` | 1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) 1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0)) |The suggestion is valid, thus clean it up.
Quoted 8 lines
Quoted 4 lines
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>Viresh, Rafael: I can put this into
rust-nextif you prefer (I consideredrust-fixes, but it is not important enough at this stage).
Signature · 1 line
viresh
Quoted 19 lines · Miguel Ojeda
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint
clippy::map_or_identity[1][2], which currently triggers in a single case:warning: expression can be simplified using `Result::unwrap_or()` --> rust/kernel/cpufreq.rs:1326:60 | 1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity = note: `-W clippy::map-or-identity` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]` help: consider using `unwrap_or` | 1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) 1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0)) |
Quoted 6 lines
The suggestion is valid, thus clean it up.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Quoted 19 lines
--- rust/kernel/cpufreq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rust/kernel/cpufreq.rs +1
-1@@ -1323,7 +1323,7 @@ impl<T: Driver> Registration<T> {// SAFETY: The C API guarantees that `cpu` refers to a valid CPU number. let cpu_id =unsafe {CpuId ::from_u32_unchecked (cpu) }; -PolicyCpu ::from_cpu (cpu_id).map_or (0 , |mut policy|T ::get (&mut policy).map_or (0 , |f| f)) +PolicyCpu ::from_cpu (cpu_id).map_or (0 , |mut policy|T ::get (&mut policy).unwrap_or (0 )) }/// Driver's `update_limit` callback. base-commit:
420dd187e1572bb7e232781bc4377a80c8eb64fb
Signature · 2 lines
Thx and BRs, Zhongqiu Han
Miguel Ojeda
AppliedQuoted 20 lines · Miguel Ojeda
Starting with Rust 1.98.0 (expected 2026-08-20), Clippy is likely introducing a new lint
clippy::map_or_identity[1][2], which currently triggers in a single case:warning: expression can be simplified using `Result::unwrap_or()` --> rust/kernel/cpufreq.rs:1326:60 | 1326 | PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_or_identity = note: `-W clippy::map-or-identity` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::map_or_identity)]` help: consider using `unwrap_or` | 1326 - PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).map_or(0, |f| f)) 1326 + PolicyCpu::from_cpu(cpu_id).map_or(0, |mut policy| T::get(&mut policy).unwrap_or(0)) |
Quoted 6 lines
The suggestion is valid, thus clean it up.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Applied to rust-next -- thanks everyone!
Cheers,
Miguel
Quoted 2 lines · Miguel Ojeda
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Adjusted to "6.18.y and later", since cpufreq was not there in 6.12.y anyway.
(I didn't use Fixes: because it isn't really a fix, although as usual it depends on how one thinks about those...)
Cheers,
Miguel