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

Merged
merged 7 commits into from
Feb 8, 2025
Merged

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.

tests/ui-toml/toml_disallowed_methods/clippy.toml Outdated Show resolved Hide resolved
clippy_config/src/types.rs Show resolved Hide resolved
clippy_config/src/types.rs Outdated Show resolved Hide resolved
clippy_lints/src/await_holding_invalid.rs Outdated Show resolved Hide resolved
@smoelius smoelius changed the title Three improvements to disallowed_methods Two improvements to disallowed_* Nov 13, 2024
@bors
Copy link
Contributor

bors commented Nov 15, 2024

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

@smoelius
Copy link
Contributor Author

@Centri3 Just so that we are on the same page, I am assuming I have done all I can with this PR. Please let me know if I have misunderstood.

Also, thanks very much for reviewing. 🙏

@Centri3
Copy link
Member

Centri3 commented Dec 16, 2024

Sorry, forgot to say. I haven't looked closely at the new changes but this definitely feels like too much when we could just have two for now. One where replacements are allowed and one where they aren't. Maybe with a shared trait to make the implementation less cumbersome and annoying... I don't know. Using const generics is definitely less understandable than that even if it's not exactly ideal. No solution really feels ideal, actually.

@smoelius
Copy link
Contributor Author

@Centri3 Is this better?

I pushed on top of the const generic stuff, but can squash once we arrive at a solution.

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.

I think I've found a pretty good solution: Using const generics is okay and probably ideal if we use type aliases. Let's do that vs this struct solution. Unfortunate it took a while for me :P

My main concern with const generics was how they had to be specified everywhere and how it's not immediately clear what it is.

With this, I think we can have just the enum afaik.

clippy_config/src/types.rs Outdated Show resolved Hide resolved
clippy_config/src/types.rs Outdated Show resolved Hide resolved
@smoelius
Copy link
Contributor Author

I think I've found a pretty good solution: Using const generics is okay and probably ideal if we use type aliases.

Is this what you are suggesting, or something more elaborate?

type DisallowedPathWithoutReplacement = DisallowedPath<false>;

@Centri3
Copy link
Member

Centri3 commented Jan 28, 2025

Ah, forgot to respond; yes pretty much.

@smoelius
Copy link
Contributor Author

The most recent commit undoes most of the commit before it (including getting rid of the AmendDiag trait) and adds a type alias like in #13669 (comment).

Could you please tell me what else is needed?

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.

Just two small things. Happy with this version

#[serde(untagged)]
pub enum DisallowedPath {
pub enum DisallowedPathEnum {
Copy link
Member

Choose a reason for hiding this comment

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

I do find this to be an odd implementation detail. I assume this is just a workaround to both derive Deserialize and have our const generic, but imo it adds way too much confusion. It should be clearer that it's not to be used elsewhere and ideally wouldn't be here at all.

Let's make this private.

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 made the enum private and I added a comment that it is not meant to be used outside of this file.

I assume this is just a workaround to both derive Deserialize and have our const generic, but imo it adds way too much confusion. It should be clearer that it's not to be used elsewhere and ideally wouldn't be here at all.

I'm not wed to this approach. Can you think of another way to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or is there something I could do to make the code more clear?

clippy_lints/src/disallowed_types.rs Outdated Show resolved Hide resolved
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.

Current approach is ok, just talking about a perfect world. Making it private is more than good enough

LGTM in this state 👍 I'll look one last time tomorrow and will likely merge then.

@Centri3 Centri3 added this pull request to the merge queue Feb 8, 2025
Merged via the queue into rust-lang:master with commit 0ff9540 Feb 8, 2025
11 checks passed
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.

5 participants