Skip to content

Commit 375bd0b

Browse files
committed
doc: add configuration snippets for match_arm_wrapping options
1 parent 9b2fd24 commit 375bd0b

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

Configurations.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,185 @@ fn foo() {
16041604
}
16051605
```
16061606

1607+
## `match_arm_wrapping`
1608+
1609+
Controls when to block wrap match arm bodies.
1610+
1611+
- **Default value**: `"Default"`
1612+
- **Possible values**: `"Default"`, `"FitFirstLine"`, `"FitEntireBody"`, `"Always"`, `"Preserve`
1613+
- **Stable**: No (tracking issue: #4896)
1614+
1615+
### Example
1616+
1617+
#### Original code
1618+
1619+
```rust
1620+
#![rustfmt::skip]
1621+
1622+
fn main() {
1623+
match lorem {
1624+
1000 => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1625+
2000 => {
1626+
println!("{}", sit)
1627+
}
1628+
3000 => panic!(),
1629+
4000 => {
1630+
()
1631+
}
1632+
5000 => this.a_very_long_function_name(foo, bar, bazz, fizz, another_argument, some_more_arguments, which_dont_fit),
1633+
}
1634+
}
1635+
```
1636+
1637+
#### `"Default"` (default):
1638+
1639+
The default block wrapping settings, as described in the Style Guide.
1640+
1641+
```rust
1642+
fn main() {
1643+
match lorem {
1644+
1000 => {
1645+
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1646+
}
1647+
2000 => {
1648+
println!("{}", sit)
1649+
}
1650+
3000 => panic!(),
1651+
4000 => (),
1652+
5000 => this.a_very_long_function_name(
1653+
foo,
1654+
bar,
1655+
bazz,
1656+
fizz,
1657+
another_argument,
1658+
some_more_arguments,
1659+
which_dont_fit,
1660+
),
1661+
}
1662+
}
1663+
```
1664+
1665+
#### `"FitFirstLine"`:
1666+
1667+
Same as the default, except don't block wrap match arms when the opening line of its body can't fit on the same line as the `=>`.
1668+
1669+
```rust
1670+
fn main() {
1671+
match lorem {
1672+
1000 =>
1673+
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x),
1674+
2000 => {
1675+
println!("{}", sit)
1676+
}
1677+
3000 => panic!(),
1678+
4000 => (),
1679+
5000 => this.a_very_long_function_name(
1680+
foo,
1681+
bar,
1682+
bazz,
1683+
fizz,
1684+
another_argument,
1685+
some_more_arguments,
1686+
which_dont_fit,
1687+
),
1688+
}
1689+
}
1690+
```
1691+
1692+
#### `"Always"`:
1693+
1694+
Always block wrap match arm bodies.
1695+
1696+
```rust
1697+
fn main() {
1698+
match lorem {
1699+
1000 => {
1700+
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1701+
}
1702+
2000 => {
1703+
println!("{}", sit)
1704+
}
1705+
3000 => {
1706+
panic!()
1707+
}
1708+
4000 => {
1709+
()
1710+
}
1711+
5000 => {
1712+
this.a_very_long_function_name(
1713+
foo,
1714+
bar,
1715+
bazz,
1716+
fizz,
1717+
another_argument,
1718+
some_more_arguments,
1719+
which_dont_fit,
1720+
)
1721+
}
1722+
}
1723+
}
1724+
```
1725+
1726+
#### `"Preserve"`:
1727+
1728+
Preserve block wrapping on match arm bodies if the developer originally had the body wrapped.
1729+
1730+
```rust
1731+
fn main() {
1732+
match lorem {
1733+
1000 => {
1734+
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1735+
}
1736+
2000 => {
1737+
println!("{}", sit)
1738+
}
1739+
3000 => panic!(),
1740+
4000 => {
1741+
()
1742+
}
1743+
5000 => this.a_very_long_function_name(
1744+
foo,
1745+
bar,
1746+
bazz,
1747+
fizz,
1748+
another_argument,
1749+
some_more_arguments,
1750+
which_dont_fit,
1751+
),
1752+
}
1753+
}
1754+
```
1755+
1756+
#### `"FitEntireBody"`:
1757+
1758+
Same as default, except block wrap the match arm if the entire body cannot fit on the same line as the `=>`.
1759+
1760+
```rust
1761+
fn main() {
1762+
match lorem {
1763+
1000 => {
1764+
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x)
1765+
}
1766+
2000 => {
1767+
println!("{}", sit)
1768+
}
1769+
3000 => panic!(),
1770+
4000 => (),
1771+
5000 => {
1772+
this.a_very_long_function_name(
1773+
foo,
1774+
bar,
1775+
bazz,
1776+
fizz,
1777+
another_argument,
1778+
some_more_arguments,
1779+
which_dont_fit,
1780+
)
1781+
}
1782+
}
1783+
}
1784+
```
1785+
16071786
## `match_block_trailing_comma`
16081787

16091788
Put a trailing comma after a block based match arm (non-block arms are not affected)

0 commit comments

Comments
 (0)