Less ideal formatting for struct pattern matching in if let
Open
Nobody has claimed this yet.
I-poor-formatting
P-low
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Given the following code:
struct Foo {
something: Option<u32>,
bar: u32,
}
fn main() {
let a = Foo {
something: Some(1),
bar: 2,
};
if let Foo { something: Some(something), .. } = a {
println!("{}", something);
}
}
rustfmt formats the if let as
if let Foo {
something: Some(something),
..
} = a
{
println!("{}", something);
}
which looks rather unfortunate...
Should probably keep the original form in this case?
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
The issue provides a Rust snippet and the rustfmt output; start by running that snippet through rustfmt and comparing it with the requested inline form. Done means the formatter no longer splits this if let pattern before the body, with the behavior covered by an appropriate rustfmt test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100