about summary refs log tree commit diff
path: root/src/doc/style-guide
AgeCommit message (Collapse)AuthorLines
2023-09-27Auto merge of #114901 - compiler-errors:style-guide-wc, r=calebcartwrightbors-6/+32
Amend style guide section for formatting where clauses in type aliases This PR has two parts: 1. Amend wording about breaking before or after the `=`, which is a style guide bugfix to align it with current rustfmt behavior. 2. Explain how to format trailing (#89122) where clauses, which are preferred in both GATs (#90076) and type aliases (#114662). r? `@joshtriplett`
2023-09-21Rollup merge of #114394 - joshtriplett:style-guide-as, r=calebcartwrightMatthias Krüger-8/+20
style-guide: Document formatting of `as` casts (mostly like a binary operator) `as` casts currently get formatted like a binary operator, except that the second line can stack several `as` casts rather than breaking them each onto their own line. Document this. As far as I can tell (cc `@calebcartwright` for verification), this is not a 2024 edition change, it just documents current behavior.
2023-09-19Rollup merge of #113383 - joshtriplett:style-bugs, r=compiler-errorsGuillaume Gomez-0/+13
style-guide: Add section on bugs, and resolving bugs
2023-08-23Remove opinions from style guide about where clauses in type alias itemsMichael Goulet-6/+9
2023-08-17style-guide: Add guidance for defining formatting for specific macrosJosh Triplett-1/+6
2023-08-16Describe how to format trailing where clausesMichael Goulet-2/+25
2023-08-16bugfix: reflect how rustfmt formats type aliasesMichael Goulet-3/+3
2023-08-04style-guide: Expand documentation on `as` casts (mostly like a binary operator)Josh Triplett-8/+20
`as` casts currently get formatted like a binary operator, except that the second line can stack several `as` casts rather than breaking them each onto their own line. Merge `as` into a subsection of the binary operators section, and then go into detail on the one difference between `as` formatting and binary operator formatting.
2023-08-01Rollup merge of #114262 - ShapelessCat:fix-style-guide-md, r=joshtriplettMatthias Krüger-152/+118
Improve the rust style guide doc - Make the levels of headings consistent in this whole document. Before this change, the highest level of headings in some file is level 1, but in most of the files the that is level 2. Not consistent. - Fix some headings - Follow the markdown linter advices - Remove redundant empty lines - Surround each heading with empty lines - Use the same symbol for different levels of unordered list entries
2023-08-01Rollup merge of #113394 - joshtriplett:style-edition-snapshot, r=calebcartwrightMatthias Krüger-0/+47
style-guide: Document style editions, start 2024 style edition Link to a snapshot for the 2015/2018/2021 style edition. This is a draft, because I'd like to wait for a few style guide fixes to merge before snapshotting the 2015/2018/2021 style edition: - https://github.com/rust-lang/rust/pull/113145 - https://github.com/rust-lang/rust/pull/113380 - https://github.com/rust-lang/rust/pull/113384 - https://github.com/rust-lang/rust/pull/113385 - https://github.com/rust-lang/rust/pull/113386 - https://github.com/rust-lang/rust/pull/113392 I'd like to wait for these for two reasons: to make it easier to see the differences between the 2015/2018/2021 style edition and the 2024 style edition (without the noise of guide-wide changes), and to minimize confusion so that bugfixes to the style guide that we include in the previous edition don't look like they're only part of the 2024 style edition. I've used "Miscellaneous `rustfmt` bugfixes" as a starting point for the list of 2024 changes, for now. We can update that when we add more 2024 changes. The section added in this PR can then serve as a baseline for our drafts of 2024 style edition changes. In the meantime, I'd like to get someone from `@rust-lang/style` to review and approve the text here; I'll update it with a commit hash when the above PRs have merged.
2023-07-31Link to the Rust edition guide for more information about editionsJosh Triplett-4/+6
2023-07-31style-guide: Document style editions, start 2024 style editionJosh Triplett-0/+45
Link to a snapshot for the 2015/2018/2021 style edition.
2023-07-31Use - instead of * for unordered listLan, Jian-53/+55
2023-07-31Improve the rust style guide docLan, Jian-134/+98
- Make the levels of headings consistent in this whole document - Fix some headings - Remove redundant empty lines - Follow the markdown linter advices to use the same symbol for different level of unordered list entries
2023-07-27docs(style-guide): don't flatten match arms with macro callCaleb Cartwright-1/+6
2023-07-21Simplify wording in guide for unbraced closuresJosh Triplett-2/+2
2023-07-21Clarify guide for unbraced closures, regarding commentsJosh Triplett-2/+2
2023-07-21Clarify guide for unbraced closures: grammatical consistencyJosh Triplett-3/+3
2023-07-21Clarify conditions for single-line blocksJosh Triplett-2/+2
Use consistent phrasing, and add an "and".
2023-07-21Use roman 4 letter instead of wordIvan Tham-2/+2
Long text without numeric numbers when numeric numbers are used are hard to read.
2023-07-21Add missing code fencecherryblossom000-0/+2
2023-07-20Clarify wording on breaking arrays across linesJosh Triplett-1/+1
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2023-07-20style-guide: Fix example to match the rule it exemplifies (and match rustfmt)Josh Triplett-1/+2
An example immediately following "Put each bound on its own line." did not put each bound on its own line.
2023-07-20style-guide: Fix typo: s/right-hand side/left-hand side/Josh Triplett-1/+1
2023-07-20style-guide: Add an additional chaining exampleJosh Triplett-1/+4
Make it clear the rule for stacking the second line on the first applies recursively, as long as the condition holds.
2023-07-20style-guide: Avoid using "should" or "may" for required parts of the default ↵Josh Triplett-220/+252
style The style guide inconsistently used language like "there should be a space" or "it should be on its own line", or "may be written on a single line", for things that are required components of the default Rust style. "should" and especially "may" come across as optional. While the style guide overall now has a statement at the top that the default style itself is a *recommendation*, the *definition* of the default style should not be ambiguous about what's part of the default style. Rewrite language in the style guide to only use "should" and "may" and similar for truly optional components of the style (e.g. things a tool cannot or should not enforce in its default configuration). In their place, either use "must", or rewrite in imperative style ("put a space", "start it on the same line"). The latter also substantially reduces the use of passive voice. This is a purely editorial change, and does not affect the semantic definition of the Rust style.
2023-07-20style-guide: Simplify the structure of a recommendation (no semantic change)Josh Triplett-3/+1
Avoid putting a sentence fragment after a list; integrate it with the sentence before the list.
2023-07-20style-guide: Fix an example to match the styleJosh Triplett-1/+1
The style guide requires a trailing comma on where clause components, but then gives an example that doesn't include one. Add the missing trailing comma.
2023-07-20style-guide: Fix typo: s/forth/fourth/gJosh Triplett-2/+2
2023-07-20style-guide: Remove material about tool configurabilityJosh Triplett-46/+2
The style guide discusses the default Rust style. Configurability of Rust formatting tools are not the domain of the style guide.
2023-07-13Correct `the` -> `there` typo in items.mdAlyssa Haroldsen-1/+1
2023-07-11Rollup merge of #113385 - joshtriplett:style-guide-cleanup-chains, ↵Jubilee-4/+3
r=calebcartwright style-guide: Fix chain example to match rustfmt behavior The style guide gave an example of breaking a multi-line chain element and all subsequent elements to a new line, but that same example and the accompanying text also had several chain items stacked on the first line. rustfmt doesn't do this, except when the rule saying to combine ``` shrt .y() ``` into ``` shrt.y() ``` applies. This is a bugfix to match rustfmt behavior, so it's not a breaking change, and it just needs a ``@rust-lang/style`` reviewer to r+.
2023-07-11Rollup merge of #113386 - joshtriplett:style-guide-combinable-expressions, ↵Matthias Krüger-0/+10
r=compiler-errors style-guide: Expand example of combinable expressions to include arrays Arrays are allowed as combinable expressions, but none of the examples show that.
2023-07-06Rollup merge of #113384 - joshtriplett:style-guide-grammar, r=compiler-errorsfee1-dead-11/+12
style-guide: Clarify grammar for small patterns (not a semantic change) The grammar as written feels ambiguous and confusing, in large part because it uses square brackets and commas in the names of non-terminals. Rewrite it to avoid symbols in the names of non-terminals, and to instead wrap terminals in backquotes. Also rename "smallntp" to "small_no_tuple" to make it self-describing.
2023-07-06Rollup merge of #113145 - ↵fee1-dead-2/+3
joshtriplett:style-guide-document-assignment-newlines, r=joshtriplett style-guide: Document newline rules for assignment operators The style guide gives general rules for binary operators including assignment, and one of those rules says to put the operator on the subsequent line; the style guide needs to explicitly state the exception of breaking *after* assignment operators rather than before. This is already what rustfmt does and what users do; this fixes the style guide to match the expected default style.
2023-07-05style-guide: Expand example of combinable expressions to include arraysJosh Triplett-0/+10
Arrays are allowed as combinable expressions, but none of the examples show that.
2023-07-05style-guide: Fix chain example to match rustfmt behaviorJosh Triplett-4/+3
The style guide gave an example of breaking a multi-line chain element and all subsequent elements to a new line, but that same example and the accompanying text also had several chain items stacked on the first line. rustfmt doesn't do this, except when the rule saying to combine ``` shrt .y() ``` into ``` shrt.y() ``` applies.
2023-07-05style-guide: Rename "smallntp" non-terminal to "small_no_tuple" for clarityJosh Triplett-4/+4
The meaning of "smallntp" was not immediately obvious at a glance. Rename it to the self-describing "small_no_tuple"
2023-07-05style-guide: Clarify grammar for small patterns (not a semantic change)Josh Triplett-11/+12
The grammar as written feels ambiguous and confusing, in large part because it uses square brackets and commas in the names of non-terminals. Rewrite it to avoid symbols in the names of non-terminals, and to instead wrap terminals in backquotes.
2023-07-05style-guide: Add chapter for nightly formattingJosh Triplett-3/+5
Co-authored-by: Michael Goulet <michael@errs.io>
2023-07-05Clarify that style guide does not cover nightly-only featuresMichael Goulet-0/+4
2023-07-05style-guide: Add section on bugs, and resolving bugsJosh Triplett-0/+13
2023-06-29Rollup merge of #113143 - ↵Matthias Krüger-1/+2
joshtriplett:style-guide-narrow-dereference-guidance, r=calebcartwright style-guide: Narrow guidance about references and dereferencing The style guide advises "prefer dereferencing to taking references", but doesn't give guidance on when that "preference" should get overridden by other considerations. Give an example of when it's fine to ignore that advice.
2023-06-29Rollup merge of #113140 - ↵Matthias Krüger-0/+5
joshtriplett:style-guide-example-multi-line-attribute, r=calebcartwright style-guide: Add an example of formatting a multi-line attribute We already say to format attributes like functions, but we didn't have an example of formatting a multi-line attribute.
2023-06-28style-guide: Document newline rules for assignment operatorsJosh Triplett-2/+3
The style guide gives general rules for binary operators including assignment, and one of those rules says to put the operator on the subsequent line; the style guide needs to explicitly state the exception of breaking *after* assignment operators rather than before. This is already what rustfmt does and what users do; this fixes the style guide to match the expected default style.
2023-06-28style-guide: Narrow guidance about references and dereferencingJosh Triplett-1/+2
The style guide advises "prefer dereferencing to taking references", but doesn't give guidance on when that "preference" should get overridden by other considerations. Give an example of when it's fine to ignore that advice.
2023-06-28style-guide: Add an example of formatting a multi-line attributeJosh Triplett-0/+5
We already say to format attributes like functions, but we didn't have an example of formatting a multi-line attribute.
2023-06-28syle-guide: Clarify let-else furtherJosh Triplett-2/+24
Give some additional examples with multi-line patterns. Make it clearer to go on to the next case if the conditions aren't met.
2023-06-24Rollup merge of #112912 - joshtriplett:style-let-else-clarifications, ↵Guillaume Gomez-43/+62
r=calebcartwright style-guide: Rewrite let-else section for clarity, without changing formatting The section as written did not cover all cases, and left some of them implicit. Rewrite it to systematically cover all cases. Place examples immediately following the corresponding case. In the process, reorder to move the simplest cases first: start with single-line and add progressively more line breaks. This does not change the meaning of the section at all, and in particular does not change the defined style for let-else statements.
2023-06-23Rollup merge of #112944 - ↵Matthias Krüger-0/+12
joshtriplett:style-guide-defaults-vs-configurability, r=compiler-errors style-guide: Add language disclaiming any effects on non-default Rust styles Make it clear that the style guide saying "must" doesn't forbid developers from doing differently (as though any power on this Earth could do that) and doesn't forbid tools from allowing any particular configuration options. Otherwise, people might wonder (for instance) if there's a semantic difference between "must" and "should" in the style guide, and whether tools are "allowed" to offer configurability of something that says "must".