Skip to content

rename KeepExisting->Preserve variant for leading match arm pipe config option #4305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
Controls whether to include a leading pipe on match arms

- **Default value**: `Never`
- **Possible values**: `Always`, `Never`, `KeepExisting`
- **Possible values**: `Always`, `Never`, `Preserve`
- **Stable**: Yes

#### `Never` (default):
Expand Down Expand Up @@ -1610,7 +1610,7 @@ fn foo() {
}
```

#### `KeepExisting`:
#### `Preserve`:
```rust
fn foo() {
match foo {
Expand Down
4 changes: 2 additions & 2 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ pub enum MatchArmLeadingPipe {
Always,
/// Never emit leading pipes on match arms
Never,
/// Maintain any existing leading pipes
KeepExisting,
/// Preserve any existing leading pipes
Preserve,
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/formatting/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ fn rewrite_match_arm(
// 2 = `| `
let (pipe_offset, pipe_str) = match context.config.match_arm_leading_pipes() {
MatchArmLeadingPipe::Never => (0, ""),
MatchArmLeadingPipe::KeepExisting if !has_leading_pipe => (0, ""),
MatchArmLeadingPipe::KeepExisting | MatchArmLeadingPipe::Always => (2, "| "),
MatchArmLeadingPipe::Preserve if !has_leading_pipe => (0, ""),
MatchArmLeadingPipe::Preserve | MatchArmLeadingPipe::Always => (2, "| "),
};

// Patterns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-match_arm_leading_pipes: KeepExisting
// rustfmt-match_arm_leading_pipes: Preserve

fn foo() {
match foo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-match_arm_leading_pipes: KeepExisting
// rustfmt-match_arm_leading_pipes: Preserve

fn foo() {
match foo {
Expand Down