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

Two improvements to disallowed_* #13669

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

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Nov 9, 2024

The improvements are as follows:


changelog: support replacements in disallowed_methods

@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 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 Nov 9, 2024
Copy link
Member

@Centri3 Centri3 left a comment

Choose a reason for hiding this comment

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

Can you add tests to ensure the spaces change works on disallowed_types? DisallowedPath is used there too, but it does its own parsing to get the DefId of types.

@@ -1,5 +1,3 @@
//@compile-flags: --crate-name conf_disallowed_methods
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason for this being here? I checked others in ui-toml and quite a few have this. I vaguely remember about this, but I don't have the specifics...

Copy link
Contributor Author

@smoelius smoelius Nov 13, 2024

Choose a reason for hiding this comment

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

Is there any reason for this being here?

I assumed it was some kind of a leftover, since conf_disallowed_methods is the name that ui_test chooses for the test crate. (Aside: with the compile-flags in place, ui_test cannot test the fix. EDIT: Mistake.)

1e1ac2b appears to be the commit that introduced the original directive. @Alexendoo do you recall why that was?

@@ -14,4 +14,5 @@ disallowed-methods = [
"conf_disallowed_methods::Struct::method",
"conf_disallowed_methods::Trait::provided_method",
"conf_disallowed_methods::Trait::implemented_method",
"conf_disallowed_methods :: path :: with :: spaces",
Copy link
Member

Choose a reason for hiding this comment

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

Was this requested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of. I assumed not allowing spaces was an oversight (but maybe I'm missing something).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see now that the .split("::") pattern appears many places, and that a larger fix is required. I will back this change out for now.

span,
self.reason().map_or_else(|| String::from("use"), ToOwned::to_owned),
replacement,
Applicability::MachineApplicable,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not fully sure this is the right choice, I would be curious first to hear what others have to say. It's not guaranteed to be machine applicable but it is something the user intends to always be replaced and it's also at the user's discretion to provide something valid, and it could get annoying. The majority of the improvement does come from the fact that it can be applied automatically after all.

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's also at the user's discretion to provide something valid...The majority of the improvement does come from the fact that it can be applied automatically after all.

This was precisely my reasoning.

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 sound. I doubt others will disagree but we'll see regardless

clippy_config/src/types.rs Outdated Show resolved Hide resolved
@@ -173,7 +174,7 @@ declare_clippy_lint! {
impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF, AWAIT_HOLDING_INVALID_TYPE]);

pub struct AwaitHolding {
def_ids: DefIdMap<(&'static str, Option<&'static str>)>,
def_ids: DefIdMap<(&'static str, &'static DisallowedPath)>,
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 should allow specifying a replacement here, even if it's never used. Also the reasoning should usually be inferred due to it being a specific lint, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point. I'll work on a fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My solution may be over-engineered. Other alternatives I considered were:

  • Use serde-untagged, but it is not in the list of permitted dependencies.
  • Implement a custom visitor like serde-untagged does, but that seemed yet more complicated.
  • Don't error during deserialization and instead warn when the replacement is discovered.

I'm open to suggestions if another approach is desired.

@smoelius smoelius changed the title Three improvements to disallowed_methods Two improvements to disallowed_* Nov 13, 2024
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.

3 participants