-
Couldn't load subscription status.
- Fork 1.8k
fix(double_parens): don't lint in proc-macros #15939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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! |
clippy_lints/src/double_parens.rs
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Fixes #15852
changelog: [
double_parens]: don't lint in proc-macros