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

Create lint passes using Conf #13088

Merged
merged 1 commit into from
Jul 17, 2024
Merged

Create lint passes using Conf #13088

merged 1 commit into from
Jul 17, 2024

Conversation

Jarcho
Copy link
Contributor

@Jarcho Jarcho commented Jul 12, 2024

This slightly reduces the amount of code changes needed to add a config to a lint and makes things makes things more consistent between passes. A dependence on the config being a static reference is also added. This would only ever be a problem if multiple crates end up compiled in a single process.

Other changes include:

  • Removing useless #[derive(..)]s
  • Removing #[must_use] on lint pass constructors.
  • Unified the parsing of the DisallowedPath struct in lint passes.
  • Update disallowed_types and await_holding_invalid messages to be consistent with other disallowed lints.
  • Remove the (from clippy.toml) message. I plan on having all the configured lints point to point to a span in clippy.toml which will be more useful.

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Jul 12, 2024

r? @Centri3

rustbot has assigned @Centri3.
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 Jul 12, 2024
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

A dependence on the config being a static reference is also added

Wasn't that that case already anyway, as the register_lints function already took the Conf as a 'static reference?


I really like those changes, thank you! Only one small comment.

pub fn new(conf: &'static Conf) -> Self {
Self {
too_large_for_stack: conf.too_large_for_stack,
msrv: conf.msrv.clone(),
Copy link
Member

Choose a reason for hiding this comment

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

Why is MSRV cloned, while everything else that is not Copy is referenced?

Copy link
Member

Choose a reason for hiding this comment

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

I assume it's because MSRV is sometimes mutated during linting when visiting #[clippy::msrv], while other configurations are not

Copy link
Member

Choose a reason for hiding this comment

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

Might be a nice use case for Cow<'static, Msrv> since it'll avoid clones if code never uses #[clippy::msrv] but not sure if that's overdoing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was taken as 'static, but it wasn't needed.

The config type should really be Option<RustcVersion>. I don't really know why Msrv exists as a type at all.

Copy link
Member

@y21 y21 Jul 12, 2024

Choose a reason for hiding this comment

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

If you mean we should always be using Option<RustcVersion> instead of Msrv (a stack of RustcVersions), then I don't see how nested #[clippy::msrv] could work (or even a single #[clippy::msrv] with a clippy.toml that also defines an msrv).

If a lint pass updates and overwrites its Option<RustcVersion> because of a #[clippy::msrv] then surely it loses the previous, enclosing msrv?

(unless you're implying that it's weird to have nested msrvs to begin with)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type stored in the config should be Option<...>. The Msrv should just be Vec<...> rather than it's own type.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. Yeah, having Msrv in the config doesn't make much sense. The type exists, because there are some convenience functions implemented on it. I thought this was nicer back then. Not married to it though, if you want to change this.

But let's not block this PR on this.

@flip1995
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 17, 2024

📌 Commit 64df401 has been approved by flip1995

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 17, 2024

⌛ Testing commit 64df401 with merge dfe8580...

bors added a commit that referenced this pull request Jul 17, 2024
Create lint passes using `Conf`

This slightly reduces the amount of code changes needed to add a config to a lint and makes things makes things more consistent between passes. A dependence on the config being a static reference is also added. This would only ever be a problem if multiple crates end up compiled in a single process.

Other changes include:
* Removing useless `#[derive(..)]`s
* Removing `#[must_use]` on lint pass constructors.
* Unified the parsing of the `DisallowedPath` struct in lint passes.
* Update `disallowed_types` and `await_holding_invalid` messages to be consistent with other disallowed lints.
* Remove the `(from clippy.toml)` message. I plan on having all the configured lints point to point to a span in `clippy.toml` which will be more useful.

changelog: none
@bors
Copy link
Contributor

bors commented Jul 17, 2024

💔 Test failed - checks-action_test

@flip1995
Copy link
Member

Please run cargo collect-metadata and push the updated lint_configurations.md file. After that r=me

* Construct lint passes by taking `Conf` by reference.
* Use `HashSet` configs in less places
* Move some `check_crate` code into the pass constructor when possible.
@Jarcho
Copy link
Contributor Author

Jarcho commented Jul 17, 2024

Metadata issue was due to doc_valid_idents being switched to a hash set causing the default value to be reordered. I'll fix that in #13084 since it's better set up to handle it.

@bors r=flip1995

@bors
Copy link
Contributor

bors commented Jul 17, 2024

📌 Commit e34c6db has been approved by flip1995

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 17, 2024

⌛ Testing commit e34c6db with merge f74037e...

@bors
Copy link
Contributor

bors commented Jul 17, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing f74037e to master...

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.

6 participants