-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Turn declare_clippy_lint into a declarative macro #13359
base: master
Are you sure you want to change the base?
Conversation
7fbe95f
to
f58aae5
Compare
Maybe: |
Recompile time seems pretty similar, maybe try |
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.
This shouldn't be in the clippy_utils
crate, as this is not something users of that crate should use.
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.
So, should it be in clippy_lints/lib.rs
? Or somewhere else maybe
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.
In clippy_lints
probably yeah. But not necessarily in lib.rs
. But lib.rs
should at least re-export it.
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.
Moving it from clippy_utils
to clippy_lints
would need prepending all lint files with use crate::declare_clippy_lint
. It can be done a simple bash script, but is it what we want?
I'm not sure why this isn't the case anymore, but when the macro was in clippy_utils
just auto-imported it into the lint modules.
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's because of #[macro_use]
rust-clippy/clippy_lints/src/lib.rs
Lines 61 to 62 in 78bdd45
#[macro_use] | |
extern crate clippy_utils; |
To do the same for a local macro you can either #[macro_export]
it or put it in a #[macro_use]
module
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 know it's because of the #[macro_use]
, but giving it to another module is not working. (I've tried both with all combinations of #[macro_export]
on the macro and #[macro_use]
on the module)
I've tried both in clippy_lints/lib.rs
, in a separate file and in the clippy_lints::utils
module. Still, not working :/
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.
Oh there's also that it needs to be defined above the lint modules that use the macro for some reason
Before using paste, I tried with
In the common |
|
Fixed, I didn't know about ${concat}, seems very useful (and possibly a general replacement for paste!) |
a63f367
to
f58aae5
Compare
Oh, something I forgot to mention. The main motivator behind this change is rust-lang/rust#125116. I need to mark some lints as always evaluated (so that, even if they are allow by default and are not manually triggered, they still run). The proc macro API is hard to work with, and I wasn't getting to the point of accepting "[eval_always: true]" into the proc macro optionally. That's the reason I translated it, and most of the reason. |
☔ The latest upstream changes (presumably #13440) made this pull request unmergeable. Please resolve the merge conflicts. |
// warn on lints, that are included in `rust-lang/rust`s bootstrap | ||
#![warn(rust_2018_idioms, unused_lifetimes)] |
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.
Part of lib.rs
already I believe
#[allow(clippy::crate_in_macro_def)] | ||
macro_rules! declare_clippy_lint { | ||
(@ | ||
// $(#[$($attrss:tt)*])* |
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.
Can be removed
rustc_session::declare_tool_lint! { | ||
$(#[doc = $lit])* | ||
#[clippy::version = $version_lit] |
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.
Indentation is a bit off here
) => { | ||
declare_clippy_lint! {@ | ||
$(#[doc = $lit])* | ||
pub $lint_name,Allow, crate::LintCategory::Restriction,$desc, |
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.
A nit but the whitespace here and in the other arms is inconsistent, each comma ought to have a space following it
$(#[clippy::version = $version:literal])? | ||
pub $lint_name:ident, | ||
internal, | ||
$desc:literal | ||
) => { | ||
declare_clippy_lint! {@ | ||
$(#[doc = $lit])* | ||
pub $lint_name,Allow, crate::LintCategory::Internal,$desc, | ||
declare_clippy_lint!(__version = $($version)?), "0.0.0" | ||
} | ||
}; | ||
|
||
// VERSION HANDLING | ||
(__version = ) => { | ||
None | ||
}; | ||
(__version = $version:literal) => { | ||
Some($version) | ||
}; |
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 don't think we have an internal lints that have a version, so we should be able to remove the __version
arms and pass Some
/None
directly
9b5963d
to
c4d3198
Compare
c4d3198
to
d562708
Compare
Ease of development, and hopefully compile times (the dependencies are still there because of ui-test). The procedural macro was doing just some very basic processing (like assigning a lint level to each category), so it didn't have a reason to stay IMO
changelog: None