Skip to content

New lint: collapsible_tuple_let#16871

Open
Souradip121 wants to merge 9 commits intorust-lang:masterfrom
Souradip121:lint-collapsible-tuple-let
Open

New lint: collapsible_tuple_let#16871
Souradip121 wants to merge 9 commits intorust-lang:masterfrom
Souradip121:lint-collapsible-tuple-let

Conversation

@Souradip121
Copy link
Copy Markdown
Contributor

@Souradip121 Souradip121 commented Apr 16, 2026

Adds the collapsible_tuple_let lint (style, warn-by-default).

Detects let (a, b) = { let x = expr; (x, expr2) }; where the block
is unnecessary — the expressions are fully separable and can be written
as individual let statements.

Closes #16750

What the lint catches

// Before
let (var1, var2) = {
    let v1 = a_complex_expression(&mut inputs)?;
    (v1, another_complex_expression(inputs))
};

// After (MachineApplicable suggestion)
let var1 = a_complex_expression(&mut inputs)?;
let var2 = another_complex_expression(inputs);

Conservative conditions (no false positives)

The lint is skipped when:

  • Block-locals appear in reversed / non-declaration order in the tuple
    (would reorder side effects)
  • A block-local is used in another block statement's initializer
  • An inline expression precedes a block-local reference in the tuple
  • The same block-local is referenced twice in the tuple
  • The outer let carries a type annotation or let-else
  • Any relevant span comes from a macro expansion

changelog: [collapsible_tuple_let]: Warn when a let tuple destructuring can be collapsed into individual let statements by removing an unnecessary block expression.

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Apr 16, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 2026

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

Lintcheck changes for 9955051

Lint Added Removed Changed
clippy::collapsible_tuple_let 1 0 0

This comment will be updated if you push new changes

@Souradip121 Souradip121 force-pushed the lint-collapsible-tuple-let branch from 4af99ed to 4f5e8af Compare April 17, 2026 12:35
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP 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.

Lint on unnecessary tuple-from-block-expr assignments

3 participants