Skip to content

Clarify version gate used for #3229 #3258

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
merged 2 commits into from
Dec 20, 2018
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
25 changes: 25 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ Please try to avoid leaving `TODO`s in the code. There are a few around, but I
wish there weren't. You can leave `FIXME`s, preferably with an issue number.


### Version-gate formatting changes

A change that introduces a different code-formatting should be gated on the
`version` configuration. This is to ensure the formatting of the current major
release is preserved, while allowing fixes to be implemented for the next
release.

This is done by conditionally guarding the change like so:

```rust
if config.version() == Version::One { // if the current major release is 1.x
// current formatting
} else {
// new formatting
}
```

This allows the user to apply the next formatting explicitly via the
configuration, while being stable by default.

When the next major release is done, the code block of the previous formatting
can be deleted, e.g., the first block in the example above when going from `1.x`
to `2.x`.


### A quick tour of Rustfmt

Rustfmt is basically a pretty printer - that is, its mode of operation is to
Expand Down
9 changes: 6 additions & 3 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,15 @@ fn rewrite_match_body(
} else {
""
};
let semicolon =
if context.config.version() == Version::Two && semicolon_for_expr(context, body) {
let semicolon = if context.config.version() == Version::One {
""
} else {
if semicolon_for_expr(context, body) {
";"
} else {
""
};
}
};
("{", format!("{}{}}}{}", semicolon, indent_str, comma))
} else {
("", String::from(","))
Expand Down