Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Sep 6, 2024

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

@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2024

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 6, 2024
@xFrednet
Copy link
Member

xFrednet commented Sep 6, 2024

Maybe:
r? @Alexendoo since I believe that you developed the macro originally?

@rustbot rustbot assigned Alexendoo and unassigned dswij Sep 6, 2024
@Alexendoo
Copy link
Member

Recompile time seems pretty similar, maybe try ${concat} instead of paste but my impression is proc macros aren't really slow

Copy link
Member

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.

Copy link
Member Author

@blyxyas blyxyas Sep 6, 2024

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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]

#[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

Copy link
Member Author

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 :/

Copy link
Member

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

@blyxyas
Copy link
Member Author

blyxyas commented Sep 6, 2024

maybe try ${concat} instead of paste

Before using paste, I tried with concat_idents, we cannot declare a value with static and concat_idents (nor do any macro magic for this to happen AFAIK)

proc macros aren't really slow

In the common nightly the diference isn't all that great, I've just tried with the parallel compiler (-Z threads=8) and the difference is 23 seconds, both from cargo clean.

@Alexendoo
Copy link
Member

Alexendoo commented Sep 6, 2024

${concat} does not have the same problems concat_idents does

@blyxyas
Copy link
Member Author

blyxyas commented Sep 6, 2024

Fixed, I didn't know about ${concat}, seems very useful (and possibly a general replacement for paste!)

@blyxyas
Copy link
Member Author

blyxyas commented Sep 13, 2024

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.

@bors
Copy link
Collaborator

bors commented Sep 22, 2024

☔ The latest upstream changes (presumably #13440) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines 1 to 2
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]
Copy link
Member

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)*])*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed

Comment on lines +17 to +15
rustc_session::declare_tool_lint! {
$(#[doc = $lit])*
#[clippy::version = $version_lit]
Copy link
Member

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,
Copy link
Member

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

Comment on lines 154 to 170
$(#[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)
};
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants