rust-lang / rust-lang/rustfmt

Multi-lined pattern of if let

Open
#3,648 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-matches P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

From https://github.com/rust-lang/rust-clippy/pull/4123#issuecomment-504837192:

     F: FnMut(&ast::Block, Option<&ast::Label>),
 {
     if let ast::ExprKind::While(_, loop_block, label)
-        | ast::ExprKind::ForLoop(_, _, loop_block, label)
-        | ast::ExprKind::Loop(loop_block, label)
-        = &expr.node
+    | ast::ExprKind::ForLoop(_, _, loop_block, label)
+    | ast::ExprKind::Loop(loop_block, label) = &expr.node
     {
         func(loop_block, label.as_ref());
     }

In this case,

  1. Should we add indentation to each clause that appears after the first one?
  2. Should we keep the expression (&expr.node) on the same line as the last clause, or put it on the next line?

Note that for multi-lined patterns of match's arm, rustfmt does not add indentation.

match some_value {
    ast::ExprKind::While(_, loop_block, label)
    | ast::ExprKind::ForLoop(_, _, loop_block, label)
    | ast::ExprKind::Loop(loop_block, label) = &expr.node
    => {
        // ...
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked rustfmt pull request comment and comparing the shown multi-line if-let pattern with the existing multi-line match-arm behavior. Determine the intended indentation and placement of the expression, then confirm the decision with formatting examples and tests for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.