Extend branches_sharing_code to match arms with a shared tail#17313
Open
sylvestre wants to merge 1 commit into
Open
Extend branches_sharing_code to match arms with a shared tail#17313sylvestre wants to merge 1 commit into
branches_sharing_code to match arms with a shared tail#17313sylvestre wants to merge 1 commit into
Conversation
Collaborator
|
r? @llogiq rustbot has assigned @llogiq. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for 4dd09d6
This comment will be updated if you push new changes |
sylvestre
marked this pull request as draft
June 28, 2026 09:16
sylvestre
force-pushed
the
match-branches-sharing-code
branch
from
June 28, 2026 11:52
8240051 to
572a588
Compare
llogiq
reviewed
Jun 28, 2026
sylvestre
force-pushed
the
match-branches-sharing-code
branch
from
June 29, 2026 13:49
b79aae8 to
3f94bf0
Compare
sylvestre
marked this pull request as ready for review
June 29, 2026 14:20
llogiq
reviewed
Jul 3, 2026
Detect `match` expressions where every arm is a block ending in the same trailing expression and the `match` is in tail position, suggesting the expression be hoisted out below the `match`. changelog: [`branches_sharing_code`]: also lint `match` expressions whose arms end with the same expression
sylvestre
force-pushed
the
match-branches-sharing-code
branch
from
July 5, 2026 13:03
3f94bf0 to
4dd09d6
Compare
Collaborator
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Contributor
Author
|
@llogiq done! thanks |
Contributor
Author
|
@llogiq can we merge it now? :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This extends
branches_sharing_codeto also fire onmatchexpressions, not justif/else.What it does
When every arm of a
matchis a block ending in the same trailing expression, and thematchis itself in tail position, that expression can be hoisted out below thematch:becomes
This came up from a real cleanup (uutils/coreutils#13129) where a function repeated
Ok(())in every arm.Guards (to keep it correct and quiet)
HirEq.lets).()tails and the all-arms-identical case are skipped.matchis the trailing expression of its enclosing block, so appending the expression after thematchis always valid. When the value is used elsewhere (e.g. bound in alet), the lint stays quiet.Lintcheck
Ran filtered to this lint:
matchhits (all inwasmi), 0 false positives.matchhits (cc,regex-syntax×2), 0 false positives.All inspected hits are genuine and the fixes compile.
Notes
if/elsewithErr(..)in one branch, so the sharedOk(())wasn't a direct arm tail — that needs early-return restructuring, out of scope here. It catches the simpler, common sibling of that pattern.branches_sharing_codeisnursery, so this is opt-in.changelog: [
branches_sharing_code]: also lintmatchexpressions whose arms end with the same expression