rust: cpufreq: fix clippy::double_parens warning in Policy doctest
Subsystems (4)
PATCH 1/1 rust: cpufreq: fix clippy::double_parens warning in Policy doctest
Clippy reports:
warning: consider removing unnecessary double parentheses
--> rust/kernel/cpufreq.rs:410:60
|
410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^Fix this by using separate format arguments.
--- rust/kernel/cpufreq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/cpufreq.rs +1 -1
@@ -407,7 +407,7 @@ pub fn to_table(mut self) -> Result<TableBox> {/// .set_fast_switch_possible(true) /// .set_transition_latency_ns(DEFAULT_TRANSITION_LATENCY_NS); /// -/// pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); +/// pr_info!("The policy details are: cpu={:?}, cur={:?}\n", policy.cpu(), policy.cur()); /// } /// ``` #[repr(transparent)]
base-commit: ecc64d2dc9ff9738d2a896beb68e02c2feaf9a02
Signature · 1 line
2.53.0
Gary Guo
reviewerQuoted 6 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This looks like a false positive, probably due to how our fmt macro works?
Best,
Gary
Quoted 24 lines
Fix this by using separate format arguments.
Fixes 6ebdd7c93177 ("rust: cpufreq: Extend abstractions for policy and driver ops")Signed-off-by John Hubbard <[email protected]>--- rust/kernel/cpufreq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rust/kernel/cpufreq.rs +1
-1@@ -407,7 +407,7 @@ pub fn to_table(mut self) -> Result<TableBox> {/// .set_fast_switch_possible(true) /// .set_transition_latency_ns(DEFAULT_TRANSITION_LATENCY_NS); /// -/// pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); +/// pr_info!("The policy details are: cpu={:?}, cur={:?}\n", policy.cpu(), policy.cur()); /// } /// ``` #[repr(transparent)] base-commit:
ecc64d2dc9ff9738d2a896beb68e02c2feaf9a02
Quoted 9 lines · Gary Guo
Quoted 6 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^This looks like a false positive, probably due to how our fmt macro works?
Probably, but in any case we need to remain clippy clean, so this work-around seems about right, yes?
thanks,
Signature · 1 line
John Hubbard
Gary Guo
reviewerQuoted 9 lines · John Hubbard
Quoted 8 lines · Gary Guo
Quoted 6 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 7 lines
Quoted 1 line
This looks like a false positive, probably due to how our fmt macro works?
Probably, but in any case we need to remain clippy clean, so this work-around seems about right, yes?
thanks,
Can you try this?
Best,
Gary
-- >8 --
rust/macros/fmt.rs +3 -2
@@ -2,7 +2,7 @@use std::collections::BTreeSet ; -use proc_macro2::{Ident ,TokenStream ,TokenTree }; +use proc_macro2::{Group ,Ident ,TokenStream ,TokenTree };use quote::quote_spanned;/// Please see [`crate::fmt`] for documentation.
@@ -69,7 +69,8 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream { } (None , acc) })(); - args.extend (quote_spanned! (first_span => #lhs #adapter (&(#rhs)))); +let rhs =Group ::new (proc_macro2::Delimiter ::None , rhs); + args.extend (quote_spanned! (first_span => #lhs #adapter (&#rhs))); } };
Quoted 39 lines · Gary Guo
Quoted 9 lines · John Hubbard
Quoted 8 lines · Gary Guo
Quoted 6 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^Quoted 7 lines
Quoted 1 line
This looks like a false positive, probably due to how our fmt macro works?
Probably, but in any case we need to remain clippy clean, so this work-around seems about right, yes?
thanks,
Can you try this?
Best,
Gary-- >8 --
rust/macros/fmt.rs +1
-1@@ -2,7 +2,7 @@use std::collections::BTreeSet ; -use proc_macro2::{Ident ,TokenStream ,TokenTree }; +use proc_macro2::{Group ,Ident ,TokenStream ,TokenTree };use quote::quote_spanned;/// Please see [`crate::fmt`] for documentation.
rust/macros/fmt.rs pub(crate) fn fmt(input: TokenStream) -> TokenStream { · line 75
Quoted 8 lines
rust/macros/fmt.rs +2
-1@@ -69,7 +69,8 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream { } (None , acc) })(); - args.extend (quote_spanned! (first_span => #lhs #adapter (&(#rhs)))); +let rhs =Group ::new (proc_macro2::Delimiter ::None , rhs); + args.extend (quote_spanned! (first_span => #lhs #adapter (&#rhs))); } };
That works nicely.
thanks,
Signature · 1 line
John Hubbard
Gary Guo
reviewerQuoted 39 lines · Gary Guo
Quoted 9 lines · John Hubbard
Quoted 8 lines · Gary Guo
Quoted 6 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^Quoted 7 lines
Quoted 1 line
This looks like a false positive, probably due to how our fmt macro works?
Probably, but in any case we need to remain clippy clean, so this work-around seems about right, yes?
thanks,
Can you try this?
Best,
Gary-- >8 --
rust/macros/fmt.rs +1
-1@@ -2,7 +2,7 @@use std::collections::BTreeSet ; -use proc_macro2::{Ident ,TokenStream ,TokenTree }; +use proc_macro2::{Group ,Ident ,TokenStream ,TokenTree };use quote::quote_spanned;/// Please see [`crate::fmt`] for documentation.
rust/macros/fmt.rs pub(crate) fn fmt(input: TokenStream) -> TokenStream { · line 73
Quoted 6 lines
rust/macros/fmt.rs +2
-1@@ -69,7 +69,8 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream { } (None , acc) })(); - args.extend (quote_spanned! (first_span => #lhs #adapter (&(#rhs)))); +let rhs =Group ::new (proc_macro2::Delimiter ::None , rhs); + args.extend (quote_spanned! (first_span => #lhs #adapter (&#rhs)));
Actually Delimiter::None isn't fully fixed [1], so perhaps let's done use this approach.
Injecting a #[allow(clippy::double_parens)] would probably a better approach today.
Best,
Gary
Quoted 2 lines
rust/macros/fmt.rs +0
-0} };
On 3/4/26 12:39 PM, Gary Guo wrote:
...
Quoted 6 lines
Actually
Delimiter::Noneisn't fully fixed [1], so perhaps let's done use this approach.Injecting a
#[allow(clippy::double_parens)]would probably a better approach today.
OK, so that gets us here:
commit 924f411d6cd0cc4d702f197566f5e701915d5760 (HEAD -> fix-clippy-double-parens-v2)
Author: John Hubbard <[email protected]> Date: Wed Mar 4 13:07:43 2026 -0800
scripts/rustdoc_test_gen.rs: suppress clippy::double_parens in doctests
The fmt! proc macro wraps each format argument like &(arg). Writing a tuple argument such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double parens, but the user has no way to avoid it because the outer parens come from the macro template.
Add clippy::double_parens to the existing #![allow(...)] in the generated doctest wrapper block. This only covers doctests, but no non-doctest code in the tree currently passes a tuple to a printing macro.
scripts/rustdoc_test_gen.rs +1 -1
@@ -208,7 +208,7 @@ macro_rules! assert_eq {{#[allow(unused)] static __DOCTEST_ANCHOR:i32 = ::core::line!()as i32 + {body_offset} +2 ; {{ -#![allow(unreachable_pub, clippy::disallowed_names)] +#![allow(unreachable_pub, clippy::disallowed_names, clippy::double_parens)] {body}main (); }}
thanks,
Signature · 1 line
John Hubbard
Gary Guo
reviewerQuoted 22 lines · John Hubbard
On 3/4/26 12:39 PM, Gary Guo wrote:
...Quoted 6 lines
Actually
Delimiter::Noneisn't fully fixed [1], so perhaps let's done use this approach.Injecting a
#[allow(clippy::double_parens)]would probably a better approach today.OK, so that gets us here:
commit
924f411d6cd0cc4d702f197566f5e701915d5760(HEAD -> fix-clippy-double-parens-v2)Author: John Hubbard <[email protected]> Date: Wed Mar 4 13:07:43 2026 -0800
scripts/rustdoc_test_gen.rs: suppressclippy::double_parensin doctestsThe fmt! proc macro wraps each format argument like &(arg). Writing a tuple argument such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double parens, but the user has no way to avoid it because the outer parens come from the macro template.
Quoted 4 lines
Add
clippy::double_parensto the existing #![allow(...)] in the generated doctest wrapper block. This only covers doctests, but no non-doctest code in the tree currently passes a tuple to a printing macro.
I think we should either disable with
#[allow(clippy::double_parens, reason = "false positive before 1.92")] fn update_policy(policy: &mut Policy) {
or disable it globally for all Rust code before 1.92.
Miguel, which one do you think is better?
Best,
Gary
Quoted 20 lines
Suggested-by Gary Guo <[email protected]>Signed-off-by John Hubbard <[email protected]>scripts/rustdoc_test_gen.rs +1
-1@@ -208,7 +208,7 @@ macro_rules! assert_eq {{#[allow(unused)] static __DOCTEST_ANCHOR:i32 = ::core::line!()as i32 + {body_offset} +2 ; {{ -#![allow(unreachable_pub, clippy::disallowed_names)] +#![allow(unreachable_pub, clippy::disallowed_names, clippy::double_parens)] {body}main (); }}thanks,
Quoted 9 lines · Gary Guo
I think we should either disable with
#[allow(clippy::double_parens, reason = "false positive before 1.92")] fn
update_policy(policy: &mut Policy){or disable it globally for all Rust code before 1.92.
Miguel, which one do you think is better?
Hmm... Disabling globally for all versions could also be an option -- not having this lint doesn't sound like a big deal, I think.
I guess it depends on how prevalent it is, i.e. how much we expect to hit it for the 1.5 years or so (since we will eventually bump above it anyway).
Or do you think the lint is very valuable?
Doing it globally for certain versions (i.e. rust_common_flags, not just KBUILD_RUSTFLAGS) requires a bit of reorganization, so for simplicity here in this series I would suggest a local allow, and then we can see later on how prevalent it is to decide whether to do it locally (whether per version or not).
I hope that helps.
Cheers,
Miguel
Miguel Ojeda
maintainerRFC PATCH 1/1 rust: kbuild: support global per-version flags
Sometimes it is useful to gate global Rust flags per compiler version. For instance, we may want to disable a lint that has false positives in a single version [1].
We already had helpers like rustc-min-version for that, which we use elsewhere, but we cannot currently use them for rust_common_flags, which contains the global flags for all Rust code (kernel and host), because rustc-min-version depends on CONFIG_RUSTC_VERSION, which does not exist when rust_common_flags is defined.
Thus, to support that, introduce rust_common_flags_per_version, defined after the include/config/auto.conf inclusion (where CONFIG_RUSTC_VERSION becomes available), and append it to rust_common_flags, KBUILD_HOSTRUSTFLAGS and KBUILD_RUSTFLAGS.
An alternative is moving all those three down, but that would mean separating them from the other KBUILD_* variables.
---
Quoted 2 lines
Doing it globally for certain versions (i.e.
rust_common_flags, not justKBUILD_RUSTFLAGS) requires a bit of reorganization,
If we wanted to go for a per-version global one, we we would need something like this patch -- sending it here so that it gets archived in case we need it.
Makefile | 8 ++++++++ 1 file changed, 8 insertions(+)
Makefile +8 -0
@@ -833,6 +833,14 @@ endif # CONFIG_TRACEPOINTS export WARN_ON_UNUSED_TRACEPOINTS +# Per-version Rust flags. These are like `rust_common_flags`, but may +# depend on the Rust compiler version (e.g. using `rustc-min-version`). +rust_common_flags_per_version := + +rust_common_flags += $(rust_common_flags_per_version) +KBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) +KBUILD_RUSTFLAGS += $(rust_common_flags_per_version) + include $(srctree)/arch/$(SRCARCH)/Makefile ifdef need-config
base-commit: 11439c4635edd669ae435eec308f4ab8a0804808 --
2.53.0
Re: [RFC PATCH] rust: kbuild: support global per-version flags
Quoted 4 lines · Miguel Ojeda
Sometimes it is useful to gate global Rust flags per compiler version. For instance, we may want to disable a lint that has false positives in a single version [1].
Regarding this, we currently have a warning on 1.85.1 for clippy::precedence and a few in 1.88.0 for clippy::uninlined_format_args, so we could use this to sort those out (plus clippy::double_parens for 1.92.0).
(We will see how hard it is to keep all these versions clean in the medium-term future when more Rust is in the kernel: we have the MSRV bump cadence now with Debian Stable, so it may be doable, but worst case we could consider relaxing the policy to just the latest stable release and whatever linux-next runs).
Cheers,
Miguel
Re: [RFC PATCH] rust: kbuild: support global per-version flags
Quoted 2 lines · Miguel Ojeda
plus
clippy::double_parensfor 1.92.0).
I mean < 1.92.0.
Cheers,
Miguel
Re: [RFC PATCH] rust: kbuild: support global per-version flags
In reply to Miguel OjedaQuoted 5 lines · Miguel Ojeda
(We will see how hard it is to keep all these versions clean in the medium-term future when more Rust is in the kernel: we have the MSRV bump cadence now with Debian Stable, so it may be doable, but worst case we could consider relaxing the policy to just the latest stable release and whatever linux-next runs).
At the minute whatever linux-next runs is whatever Debian stable has!
Re: [RFC PATCH] rust: kbuild: support global per-version flags
Quoted 2 lines · Mark Brown
At the minute whatever linux-next runs is whatever Debian stable has!
Great, that would mean we are effectively keeping the minimum one clean, which is in a way the best we can do (apart from the maximum) if we don't try to keep every single version clean between them.
It is also what we have asked patch submitters to do so far, i.e. to keep things clean for both the minimum and the maximum:
https://rust-for-linux.com/contributing#submit-checklist-addendum
Thanks for confirming!
Cheers,
Miguel
Re: [RFC PATCH] rust: kbuild: support global per-version flags
Quoted 7 lines · Miguel Ojeda
Quoted 1 line · Mark Brown
At the minute whatever linux-next runs is whatever Debian stable has!
Great, that would mean we are effectively keeping the minimum one clean, which is in a way the best we can do (apart from the maximum) if we don't try to keep every single version clean between them.
Note that I've not started running with clippy yet, currently due to Linus' tree having:
error: current MSRV (Minimum Supported Rust Version) is 1.78.0 but this item is stable since 1.79.0
--> /tmp/next/build/rust/kernel/ptr/projection.rs:79:26
|
79 | if self >= slice.len() {
| ^^^^^
| = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
= note: -D clippy::incompatible-msrv implied by -D warnings
= help: to override -D warnings add #[allow(clippy::incompatible_msrv)]
error: current MSRV (Minimum Supported Rust Version) is 1.78.0 but this item is stable since 1.79.0
--> /tmp/next/build/rust/kernel/ptr/projection.rs:95:29
|
95 | if self.end > slice.len() {
| ^^^^^
|= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
error: current MSRV (Minimum Supported Rust Version) is 1.78.0 but this item is stable since 1.79.0
--> /tmp/next/build/rust/kernel/ptr/projection.rs:121:28
|
121 | (self.start..slice.len()).get(slice)
| ^^^^^
|= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
error: current MSRV (Minimum Supported Rust Version) is 1.78.0 but this item is stable since 1.79.0
--> /tmp/next/build/rust/kernel/ptr.rs:253:11
|
253 | p.len() * size_of::<T>()
| ^^^^^
|= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
error: aborting due to 4 previous errors
Danilo Krummrich
reviewerRe: [RFC PATCH] rust: kbuild: support global per-version flags
Quoted 14 lines · Mark Brown
Quoted 7 lines · Miguel Ojeda
Quoted 1 line · Mark Brown
At the minute whatever linux-next runs is whatever Debian stable has!
Great, that would mean we are effectively keeping the minimum one clean, which is in a way the best we can do (apart from the maximum) if we don't try to keep every single version clean between them.
Note that I've not started running with clippy yet, currently due to Linus' tree having:
error: current MSRV (Minimum Supported Rust Version) is
1.78.0but this item is stable since1.79.0
-->/tmp/next/build/rust/kernel/ptr/projection.rs:79:26
Quoted 7 lines
| 79 | if self >= slice.len() { | ^^^^^ |= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
= note:-D clippy::incompatible-msrvimplied by-D warnings
= help: to override-D warningsadd#[allow(clippy::incompatible_msrv)]
Interesting, I neither see this with 1.78.0 nor 1.94.0, but I can indeed reproduce this with 1.85.1.
Re: [RFC PATCH] rust: kbuild: support global per-version flags
In reply to Mark BrownQuoted 5 lines · Mark Brown
Note that I've not started running with clippy yet, currently due to Linus' tree having:
error: current MSRV (Minimum Supported Rust Version) is
1.78.0but this item is stable since1.79.0
This was fixed in upstream Clippy in Rust 1.90.0 due to a request we made (thanks to Tamir):
https://github.com/rust-lang/rust-clippy/issues/14425
I would suggest to allow the lint locally (perhaps once at the top of the file). This will go away this cycle since I am going to bump the minimum version to Debian Trixie's.
Alternatively, we could use the patch above to add clippy::incompatible_msrv, but that is more involved, and allowing it locally is what we did elsewhere too.
Cheers,
Miguel
Gary Guo
reviewerQuoted 7 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This looks like a Clippy bug that's fixed in latest Clippy:
https://github.com/rust-lang/rust-clippy/pull/15939
Best,
Gary
Quoted 23 lines
Fix this by using separate format arguments.
Fixes 6ebdd7c93177 ("rust: cpufreq: Extend abstractions for policy and driver ops")Signed-off-by John Hubbard <[email protected]>--- rust/kernel/cpufreq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rust/kernel/cpufreq.rs +1
-1@@ -407,7 +407,7 @@ pub fn to_table(mut self) -> Result<TableBox> {/// .set_fast_switch_possible(true) /// .set_transition_latency_ns(DEFAULT_TRANSITION_LATENCY_NS); /// -/// pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); +/// pr_info!("The policy details are: cpu={:?}, cur={:?}\n", policy.cpu(), policy.cur()); /// } /// ``` #[repr(transparent)] base-commit:
ecc64d2dc9ff9738d2a896beb68e02c2feaf9a02
Quoted 9 lines · Gary Guo
Quoted 7 lines · John Hubbard
Clippy reports:
warning: consider removing unnecessary double parentheses --> rust/kernel/cpufreq.rs:410:60 | 410 | pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 4 lines
This looks like a Clippy bug that's fixed in latest Clippy:
Looks like it, yes. I'm using the 1.78 toolchain because it is the oldest and we are supposed to verify that builds work with the oldest:
<blueforge> linux-github (fix-clippy-double-parens-v2)$ clippy-driver --version clippy 0.1.78 (9b00956 2024-04-29)
<blueforge> linux-github (fix-clippy-double-parens-v2)$ rustup which clippy-driver /home/jhubbard/.rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/bin/clippy-driver
I'm not sure if this means we should workaround the problem or not.
thanks,
Signature · 1 line
John Hubbard