Multi-lined pattern of if let
Open
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,
- Should we add indentation to each clause that appears after the first one?
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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