Skip to content

match_same_arms, ifs_same_cond: lint once per same arm/condition #14637

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

Merged
merged 1 commit into from
May 16, 2025

Conversation

Alexendoo
Copy link
Member

A large fraction of the lints emitted in CI lintcheck come from this match, currently for n same arms ((n - 1) * n)/2 lints are emitted, with this change it will be emitted as a single lint

Also fixes #13835

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2025

r? @llogiq

rustbot has assigned @llogiq.
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 Apr 16, 2025
@Alexendoo
Copy link
Member Author

110 added, 268700 removed, 172 changed

😅

Copy link
Contributor

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Really nice improvement.

/// `exprs`
/// Returns a list of groups where elements in each group are equal according to `eq`
///
/// Groups contain at least two elements and appear in the order they occur in `exprs`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Groups contain at least two elements and appear in the order they occur in `exprs`
/// Groups contain at least two elements which appear in the order they occur in `exprs`

The groups themselves are not ordered, only elements within a group are.

Copy link
Member Author

Choose a reason for hiding this comment

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

The groups are also ordered, updated the comment to say that

group.iter().map(|(_, arm)| arm.span).collect_vec(),
"these match arms have identical bodies",
|diag| {
diag.help("make the arms return different values");
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this suggestion a bit strange. While it sounds logical to group the arms if possible, changing the body value means changing the semantics.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's from the basis that the same arms may not be intentional and so inherently require changing the semantics, reworded it to state that explicitly

@samueltardieu
Copy link
Contributor

@Alexendoo This looks really nice (see the two nitpicking comments). I like how the patterns stay in order compared to the previous implementation.

I prefer to wait until 1.88 is branched out of master (in two days) before merging this in case an unplanned Clippy sync happens in the meantime. Given the scope of the change, a full nightly + beta cycle will be useful to catch any oversight.

r? @samueltardieu

@rustbot rustbot assigned samueltardieu and unassigned llogiq May 7, 2025
@samueltardieu
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 13, 2025
@Alexendoo Alexendoo force-pushed the group-search-same branch from d6ccb71 to 39ab00a Compare May 16, 2025 12:56
@Alexendoo Alexendoo added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 16, 2025
@samueltardieu samueltardieu added this pull request to the merge queue May 16, 2025
@samueltardieu
Copy link
Contributor

Thanks!

Merged via the queue into rust-lang:master with commit feb70b5 May 16, 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.

Removing @rust-nofix from match_same_arms requires lint fixes
4 participants