Merge pull request #2383 from davidalber/range-spaces-in-match
Extending `spaces_around_ranges` to ranges in match arm patterns
This commit is contained in:
commit
dfae6a99c0
@ -1468,7 +1468,7 @@ struct Foo {
|
||||
|
||||
## `spaces_around_ranges`
|
||||
|
||||
Put spaces around the .. and ... range operators
|
||||
Put spaces around the .., ..=, and ... range operators
|
||||
|
||||
- **Default value**: `false`
|
||||
- **Possible values**: `true`, `false`
|
||||
@ -1477,13 +1477,49 @@ Put spaces around the .. and ... range operators
|
||||
#### `false` (default):
|
||||
|
||||
```rust
|
||||
let lorem = 0..10;
|
||||
fn main() {
|
||||
let lorem = 0..10;
|
||||
let ipsum = 0..=10;
|
||||
|
||||
match lorem {
|
||||
1..5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1..=5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1...5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### `true`:
|
||||
|
||||
```rust
|
||||
let lorem = 0 .. 10;
|
||||
fn main() {
|
||||
let lorem = 0 .. 10;
|
||||
let ipsum = 0 ..= 10;
|
||||
|
||||
match lorem {
|
||||
1 .. 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1 ..= 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1 ... 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## `spaces_within_parens_and_brackets`
|
||||
|
@ -65,10 +65,15 @@ impl Rewrite for Pat {
|
||||
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
|
||||
RangeEnd::Excluded => "..",
|
||||
};
|
||||
let infix = if context.config.spaces_around_ranges() {
|
||||
format!(" {} ", infix)
|
||||
} else {
|
||||
infix.to_owned()
|
||||
};
|
||||
rewrite_pair(
|
||||
&**lhs,
|
||||
&**rhs,
|
||||
PairParts::new("", infix, ""),
|
||||
PairParts::new("", &infix, ""),
|
||||
context,
|
||||
shape,
|
||||
SeparatorPlace::Front,
|
||||
|
@ -2,5 +2,21 @@
|
||||
// Spaces around ranges
|
||||
|
||||
fn main() {
|
||||
let lorem = 0..10;
|
||||
let lorem = 0 .. 10;
|
||||
let ipsum = 0 ..= 10;
|
||||
|
||||
match lorem {
|
||||
1 .. 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1 ..= 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1 ... 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,20 @@
|
||||
|
||||
fn main() {
|
||||
let lorem = 0..10;
|
||||
let ipsum = 0..=10;
|
||||
|
||||
match lorem {
|
||||
1..5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1..=5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1...5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,20 @@
|
||||
|
||||
fn main() {
|
||||
let lorem = 0..10;
|
||||
let ipsum = 0..=10;
|
||||
|
||||
match lorem {
|
||||
1..5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1..=5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1...5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,20 @@
|
||||
|
||||
fn main() {
|
||||
let lorem = 0 .. 10;
|
||||
let ipsum = 0 ..= 10;
|
||||
|
||||
match lorem {
|
||||
1 .. 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1 ..= 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
|
||||
match lorem {
|
||||
1 ... 5 => foo(),
|
||||
_ => bar,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user