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

internal: Fix Clippy warnings and replace some if lets with match #10440

Merged
merged 4 commits into from
Oct 5, 2021

Conversation

lunacookies
Copy link
Contributor

I decided to try fixing a bunch of Clippy warnings. I am aware of this project’s opinion of Clippy (I have read both rust-lang/clippy#5537 and rust-analyzer/rowan#57 (comment)), so I totally understand if part of or the entirety of this PR is rejected. In particular, I can see how the semicolons and if let vs match commits provide comparatively little benefit when compared to the ensuing churn.

I tried to separate each kind of change into its own commit to make it easier to discard certain changes. I also only applied Clippy suggestions where I thought they provided a definite improvement to the code (apart from semicolons, which is IMO more of a formatting/consistency question than a linting question). In the end I accumulated a list of 28 Clippy lints I ignored entirely.

Sidenote: I should really have asked about this on Zulip before going through all 1,555 if lets in the codebase to decide which ones definitely look better as match :P

Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

The changes look good to me.
Though I am personally not a fan of "Replace if let Some(_) = foo with if let foo.is_some()", I prefer pattern matches. Then again my preference doesn't align with our style guide in some ways anyways which I assume this might apply to as well(would be a good addition to it at least)

Will wait for another opinion before merging.

@lunacookies
Copy link
Contributor Author

lunacookies commented Oct 3, 2021

To ensure the semicolon changes remain in future, would it be good to add a check just for that lint to CI?

Edit: one way this could be done is by adding a test that checks the exit code of cargo clippy -- --allow clippy::all --deny clippy::semicolon_if_nothing_returned to tidy.rs.

@lunacookies
Copy link
Contributor Author

Sorry for the force push, just noticed I wrote if let foo.is_some() instead of if foo.is_some() in the commit message.

@Veykril
Copy link
Member

Veykril commented Oct 4, 2021

To ensure the semicolon changes remain in future, would it be good to add a check just for that lint to CI?

I feel like that might become very annoying(wish rustfmt would just fix that since it's a change that wouldn't change semantics anyways).

@lunacookies
Copy link
Contributor Author

Hmm, good point. I too wish rustfmt would handle adding semicolons in these places automatically. Doing this kind of formatting requires type information, so I can definitely see why it hasn’t been implemented. Is there any point in making semicolons consistent now if they’ll just regress over time?

@Veykril
Copy link
Member

Veykril commented Oct 4, 2021

Right that does require type info...

I mean it doesn't hurt making these consistent every now and then if its just running a clippy fix. At least its better than having these accumulate more and more I feel like.

@lunacookies
Copy link
Contributor Author

Unfortunately fixing semicolons is not something done by cargo clippy --fix at the moment. I took a short look through the Clippy source code, but I can’t find anything that specifically implements fixes for certain lints.

@Veykril
Copy link
Member

Veykril commented Oct 5, 2021

Oh that's a shame, sounds like something that could have a simple fix to it.

I'll go ahead and merge this now before this might run into merge conflicts as this applies none of the weird clippy lints.
bors r+

@bors
Copy link
Contributor

bors bot commented Oct 5, 2021

@bors bors bot merged commit 86c534f into rust-lang:master Oct 5, 2021
@lunacookies lunacookies deleted the clippy-and-if-let branch October 5, 2021 10:12
@lnicola lnicola changed the title Fix Clippy warnings and replace some if lets with match internal: Fix Clippy warnings and replace some if lets with match Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants