fix(double_parens): don't lint in proc-macros#15939
Conversation
|
rustbot has assigned @samueltardieu. Use |
|
No changes for 02e4516 |
|
uhh.... Oh, these are probably caused by the changes the |
|
I won't have time to review this right now, so let's reroll. r? clippy |
|
Ohh, apparently only |
2f8af6b to
9ebd9a6
Compare
|
#15940 might also relate to this? |
It probably does, but it looks like the rust-clippy/clippy_utils/src/check_proc_macro.rs Lines 149 to 156 in 8ff0cf8 is taken, which makes the I must admit I have no idea how to fix this -- maybe it'd be the easiest to just not lint in any code coming from an expansion |
|
This shouldn't be trying using
|
e68621b to
b4a3770
Compare
|
Thank you very much @Jarcho, that worked! |
| fn check_source(cx: &EarlyContext<'_>, inner: &Expr) -> bool { | ||
| if let Some(sfr) = inner.span.get_source_range(cx) | ||
| // this line is copied from `SourceFileRange::as_str`, but | ||
| // -- doesn't load `external_src`, to avoid linting in external macros (?) |
There was a problem hiding this comment.
is this comment correct?
There was a problem hiding this comment.
If it's an imported source file then it's definitely from a external macro, but that's not the only case that is. You'll still need an in_external_macro check.
You should just SourceFileRange::as_str since that will be changed to not loading external sources. At least on lint relies on this and nobody has thoroughly checked every use to see if there are others.
There was a problem hiding this comment.
You should just
SourceFileRange::as_str
I think that wouldn't work because of the consideration on the next line of the comment -- since we want to look not only at the range in sfr but also at the text surrounding it, we'll need to do the slicing manually
You'll still need an
in_external_macrocheck.
It looks like a test case using external! is already not getting linted as is -- do you maybe know why that would be / what other test will point out the need for in_external_macro?
There was a problem hiding this comment.
It looks like a test case using external! is already not getting linted as is -- do you maybe know why that would be / what other test will point out the need for in_external_macro?
external! just sets all the spans to the proc macro's mixed site span which has a location encompassing the entire call. If it used Span::resolved_at or Span::located_at you could get something which could share the parenthesis' location while still being detected as from an external macro.
There was a problem hiding this comment.
I think that wouldn't work because of the consideration on the next line of the comment -- since we want to look not only at the range in sfr but also at the text surrounding it, we'll need to do the slicing manually
Right. Ignore that comment then.
There was a problem hiding this comment.
It looks like a test case using
external!is already not getting linted as is -- do you maybe know why that would be / what other test will point out the need forin_external_macro?
Sorry, just noticed this -- wouldn't the test case with macro_rules::double_parens be testing exactly that, an external macro? I even tried adding some expressions from the derive test:
#[macro_export]
macro_rules! double_parens {
($a:expr, $b:expr, $c:expr, $d:expr) => {{
let a = ($a);
let b = ((5));
let c = std::convert::identity((5));
InterruptMask((($a.union($b).union($c).union($d)).into_bits()) as u32)
}};
}but it sill won't lint...
There was a problem hiding this comment.
Meanwhile if I create and call the same macro in the test file, everything gets linted as expected. So the lint does seem to handle internal/external distinction correctly already -- the answer is how..
There was a problem hiding this comment.
No. If the source is from a different crate then it's loaded via external_src. I don't think macro_rules macros on their own can cause it.
e2913cb to
21a787d
Compare
|
Can you remove the changes to |
|
Done. Also added |
[beta] Clippy beta backport All 3 PRs are fixing bugs that were introduced in 1.92 (current beta) and would land on the next stable. - rust-lang/rust-clippy#16079 - rust-lang/rust-clippy#15984 - rust-lang/rust-clippy#15939 I verified that all of those commits are already synced to `main`. r? `@Mark-Simulacrum`
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double_parens, but it is a false positive fixed in Clippy 1.92 (rust-lang/rust-clippy#15939). Suppress the warning locally with a reason attribute so it can be removed once the minimum toolchain moves past 1.92. Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double_parens, but it is a false positive fixed in Clippy 1.92 (rust-lang/rust-clippy#15939). Suppress the warning on the affected doctest function with a reason attribute so it can be removed once the minimum toolchain moves past 1.92. Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double_parens, but it is a false positive fixed in Clippy 1.92 (rust-lang/rust-clippy#15939). Suppress the warning on the affected doctest function with a reason attribute so it can be removed once the minimum toolchain moves past 1.92. Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double_parens, but it is a false positive fixed in Clippy 1.92 [1] [2]. Suppress the warning on the affected doctest function with a reason attribute so it can be removed once the minimum toolchain moves past 1.92. Link: rust-lang/rust-clippy#15852 [1] Link: rust-lang/rust-clippy#15939 [2] Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Cc: stable@vger.kernel.org # Needed in 6.16.y and later. Link: https://patch.msgid.link/20260312041934.362840-2-jhubbard@nvidia.com [ Added Link tags with full URLs. Reworded reason string to match the style of others elsewhere. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double_parens, but it is a false positive fixed in Clippy 1.92 [1] [2]. Suppress the warning on the affected doctest function with a reason attribute so it can be removed once the minimum toolchain moves past 1.92. [ We may end up deciding to support per-version Clippy lints, in which case we will need [3]. In the future, if [4] gets fixed, we may be able to use `Delimiter::None` as Gary suggested in [5]. Link: https://lore.kernel.org/rust-for-linux/20260307170929.153892-1-ojeda@kernel.org/ [3] Link: rust-lang/rust#67062 [4] Link: https://lore.kernel.org/rust-for-linux/DGUA5GY2DGYN.3PG0FKLG7GFN1@garyguo.net/ [5] - Miguel ] Link: rust-lang/rust-clippy#15852 [1] Link: rust-lang/rust-clippy#15939 [2] Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://patch.msgid.link/20260312041934.362840-2-jhubbard@nvidia.com [ Reworded to replace GitHub-like short link with full URLs in Link tags. Reworded reason string to match the style of a couple others we have elsewhere. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that as double_parens, but it is a false positive fixed in Clippy 1.92 [1] [2]. Suppress the warning on the affected doctest function with a reason attribute so it can be removed once the minimum toolchain moves past 1.92. [ We may end up deciding to support per-version Clippy lints, in which case we will need [3]. In the future, if [4] gets fixed, we may be able to use `Delimiter::None` as Gary suggested in [5]. Link: https://lore.kernel.org/rust-for-linux/20260307170929.153892-1-ojeda@kernel.org/ [3] Link: rust-lang/rust#67062 [4] Link: https://lore.kernel.org/rust-for-linux/DGUA5GY2DGYN.3PG0FKLG7GFN1@garyguo.net/ [5] - Miguel ] Link: rust-lang/rust-clippy#15852 [1] Link: rust-lang/rust-clippy#15939 [2] Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://patch.msgid.link/20260312041934.362840-2-jhubbard@nvidia.com [ Reworded to replace GitHub-like short link with full URLs in Link tags. Reworded reason string to match the style of a couple others we have elsewhere. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Fixes #15852
changelog: [
double_parens]: don't lint in proc-macros