]> git.lizzy.rs Git - rust.git/blobdiff - Contributing.md
Merge pull request #3333 from topecongiro/macro-arg-single-keyword
[rust.git] / Contributing.md
index 23b3de3e8fa006526cc693546492a74594f5c095..1cf6a86e54696327f0604e6faa1a452791b14871 100644 (file)
@@ -1,7 +1,7 @@
 # Contributing
 
 There are many ways to contribute to Rustfmt. This document lays out what they
-are and has information for how to get started. If you have any questions about
+are and has information on how to get started. If you have any questions about
 contributing or need help with anything, please ask in the WG-Rustfmt channel
 on [Discord](https://discordapp.com/invite/rust-lang). Feel free to also ask questions
 on issues, or file new issues specifically to get help.
@@ -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
@@ -129,14 +154,14 @@ can.
 
 Our primary tool here is to look between spans for text we've missed. For
 example, in a function call `foo(a, b)`, we have spans for `a` and `b`, in this
-case there is only a comma and a single space between the end of `a` and the
+case, there is only a comma and a single space between the end of `a` and the
 start of `b`, so there is nothing much to do. But if we look at
 `foo(a /* a comment */, b)`, then between `a` and `b` we find the comment.
 
 At a higher level, Rustfmt has machinery so that we account for text between
 'top level' items. Then we can reproduce that text pretty much verbatim. We only
 count spans we actually reformat, so if we can't format a span it is not missed
-completely, but is reproduced in the output without being formatted. This is
+completely but is reproduced in the output without being formatted. This is
 mostly handled in [src/missed_spans.rs](src/missed_spans.rs). See also `FmtVisitor::last_pos` in
 [src/visitor.rs](src/visitor.rs).
 
@@ -152,7 +177,7 @@ then walk their own children.
 The `Rewrite` trait is defined in [src/rewrite.rs](src/rewrite.rs). It is implemented for many
 things that can be rewritten, mostly AST nodes. It has a single function,
 `rewrite`, which is called to rewrite `self` into an `Option<String>`. The
-arguments are `width` which is the horizontal space we write into, and `offset`
+arguments are `width` which is the horizontal space we write into and `offset`
 which is how much we are currently indented from the lhs of the page. We also
 take a context which contains information used for parsing, the current block
 indent, and a configuration (see below).
@@ -199,11 +224,11 @@ space we have. Something like `available_space = budget - overhead`. Since
 widths are unsized integers, this would cause underflow. Therefore we use
 checked subtraction: `available_space = budget.checked_sub(overhead)?`.
 `checked_sub` returns an `Option`, and if we would underflow `?` returns
-`None`, otherwise we proceed with the computed space.
+`None`, otherwise, we proceed with the computed space.
 
 ##### Rewrite of list-like expressions
 
-Much syntax in Rust is lists: lists of arguments, lists of fields, lists of
+Much of the syntax in Rust is lists: lists of arguments, lists of fields, lists of
 array elements, etc. We have some generic code to handle lists, including how to
 space them in horizontal and vertical space, indentation, comments between
 items, trailing separators, etc. However, since there are so many options, the