Skip to content

Commit a1ee7e9

Browse files
authored
Merge pull request rust-lang#3258 from scampi/version-gate
Clarify version gate used for rust-lang#3229
2 parents 3f6ea77 + e305262 commit a1ee7e9

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

Contributing.md

+25
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ Please try to avoid leaving `TODO`s in the code. There are a few around, but I
9191
wish there weren't. You can leave `FIXME`s, preferably with an issue number.
9292

9393

94+
### Version-gate formatting changes
95+
96+
A change that introduces a different code-formatting should be gated on the
97+
`version` configuration. This is to ensure the formatting of the current major
98+
release is preserved, while allowing fixes to be implemented for the next
99+
release.
100+
101+
This is done by conditionally guarding the change like so:
102+
103+
```rust
104+
if config.version() == Version::One { // if the current major release is 1.x
105+
// current formatting
106+
} else {
107+
// new formatting
108+
}
109+
```
110+
111+
This allows the user to apply the next formatting explicitly via the
112+
configuration, while being stable by default.
113+
114+
When the next major release is done, the code block of the previous formatting
115+
can be deleted, e.g., the first block in the example above when going from `1.x`
116+
to `2.x`.
117+
118+
94119
### A quick tour of Rustfmt
95120

96121
Rustfmt is basically a pretty printer - that is, its mode of operation is to

src/matches.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,15 @@ fn rewrite_match_body(
413413
} else {
414414
""
415415
};
416-
let semicolon =
417-
if context.config.version() == Version::Two && semicolon_for_expr(context, body) {
416+
let semicolon = if context.config.version() == Version::One {
417+
""
418+
} else {
419+
if semicolon_for_expr(context, body) {
418420
";"
419421
} else {
420422
""
421-
};
423+
}
424+
};
422425
("{", format!("{}{}}}{}", semicolon, indent_str, comma))
423426
} else {
424427
("", String::from(","))

0 commit comments

Comments
 (0)