about summary refs log tree commit diff
path: root/src/doc/style-guide
AgeCommit message (Collapse)AuthorLines
2025-09-03Add note about trailing whitespace in string literals.Josh Triplett-1/+4
2025-08-21style-guide: Document absence of trailing whitespaceJosh Triplett-2/+7
2025-05-07style: Never break within a nullary function call `func()` or a unit literal ↵Josh Triplett-0/+13
`()`
2025-04-08Stabilize precise capture syntax in style guidexizheyin-12/+12
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-06doc(style): add let-chain rulesCaleb Cartwright-6/+72
2025-01-30Revert "[style 2024] Combine all last arg delimited exprs"Michael Goulet-52/+7
This reverts commit bed0c9d97f098b71f4968808ab16d9ba40bce49c.
2024-12-31Rollup merge of #134975 - ehuss:revert-style-guide-rhs-break, r=compiler-errorsTrevor Gross-28/+0
Revert style guide rhs break This reverts https://github.com/rust-lang/rust/pull/132369 and https://github.com/rust-lang/rust/pull/119838. The style-guide change for indentation of rhs was not implemented in time for the 2024 style edition. See tracking issue https://github.com/rust-lang/rust/issues/132380. cc #134974 for the other style guide change in 2024. r? ``@compiler-errors``
2024-12-31Revert "Rollup merge of #119838 - joshtriplett:style-guide-binop-indent, ↵Eric Huss-33/+0
r=compiler-errors" This reverts commit 36287830a22897fc05f33f615291df7efe8cad20, reversing changes made to 31026b7fe3e510a646eddeda838d1f0859f892e7.
2024-12-31Revert "Rollup merge of #132369 - ↵Eric Huss-6/+11
joshtriplett:style-guide-binop-heuristic-assignment-only, r=calebcartwright" This reverts commit 348d28052b1717f152b04725492c256c3409a361, reversing changes made to 526c67f37be44688345aec14f7b1c5926f4a59a7.
2024-12-31Revert "Rollup merge of #119515 - ↵Eric Huss-27/+4
joshtriplett:style-guide-gat-where-clause-same-line, r=compiler-errors" This reverts commit 4d1cce9de5af0e74169c6508d44c99b546d7abde, reversing changes made to 030a12ce2b1ee42f2d8837b1b500fd9cf12ea191.
2024-10-30style-guide: Only use the new binop heuristic for assignmentsJosh Triplett-11/+6
This avoids pathological cases where chains of binops get progressively deeper.
2024-08-26Add unsafe to extern blocks in style guideSantiago Pastorino-2/+2
2024-07-17style-guide: Clarify version-sortingJosh Triplett-21/+23
Every time we apply version-sorting, we also say to sort non-lowercase before lowercase. This seems likely to be what we'll want for future sorting, as well. For simplicity, just incorporate that into the definition, "unless otherwise specified".
2024-06-20Add nightly style guide section for precise_capturingMichael Goulet-0/+12
2024-05-14Wording improvementJosh Triplett-1/+1
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2024-05-14Fix missing wordJosh Triplett-1/+1
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2024-05-14style-guide: When breaking binops handle multi-line first operand betterJosh Triplett-0/+33
Use the indentation of the *last* line of the first operand, not the first. Fixes https://github.com/rust-lang/style-team/issues/189
2024-05-13Reword formatting for where clausesJosh Triplett-1/+1
Suggested-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2024-05-13style-guide: Also format where clauses on one line for short function declsJosh Triplett-5/+15
2024-05-13style-guide: Not all where clauses can be written as inline boundsJosh Triplett-1/+1
2024-05-13style-guide: Give a second example for associated type formattingJosh Triplett-0/+1
Show an example that has bounds.
2024-05-13style-guide: Format single associated type `where` clauses on the same lineJosh Triplett-1/+13
In particular, lifetime-generic associated types often have a `where Self: 'a` bound, which we can format on the same line.
2024-01-24Rollup merge of #114764 - pitaj:style-delimited-expressions, r=joshtriplettLeón Orell Valerian Liehr-7/+52
[style edition 2024] Combine all delimited exprs as last argument Closes rust-lang/style-team#149 If this is merged, the rustfmt option `overflow_delimited_expr` should be enabled by default in style edition 2024. [Rendered](https://github.com/pitaj/rust/blob/style-delimited-expressions/src/doc/style-guide/src/expressions.md#combinable-expressions) r? joshtriplett
2024-01-11Rollup merge of #115046 - joshtriplett:master, r=compiler-errorsMatthias Krüger-11/+104
Use version-sorting for all sorting Add a description of a version-sorting algorithm. (This algorithm does not precisely match `strverscmp`; it's intentionally simpler in its handling of leading zeroes, and produces a result easier for humans to easily understand and do by hand.) Change all references to sorting to use version-sorting. Change all references to "ASCIIbetically" to instead say "sort non-lowercase before lowercase".
2023-12-22style-guide: Rework version-sorting algorithmJosh Triplett-22/+69
Treat numeric chunks with equal value but differing numbers of leading zeroes as equal, unless we get to the end of the entire string in which case we use "more leading zeroes in the earliest differing chunk" as a tiebreaker. Treat `_` as a word separator, sorting it before anything other than space. Give more examples.
2023-11-29[style 2024] Combine all last arg delimited exprsPeter Jaszkowiak-7/+52
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-27Clarify "as normal" -> "lexicographically"Josh Triplett-4/+5
2023-08-23Remove opinions from style guide about where clauses in type alias itemsMichael Goulet-6/+9
2023-08-21Streamline description of versionsort (incorporate suggestion from Ralf)Josh Triplett-4/+3
2023-08-21Clarify that version-sorting looks for the *longest* sequence of digitsJosh Triplett-3/+4
2023-08-21Make an implementation note on version-sorting accurateJosh Triplett-3/+3
2023-08-21Use version-sorting for all sortingJosh Triplett-11/+56
Add a description of a version-sorting algorithm. (This algorithm does not precisely match `strverscmp`; it's intentionally simpler in its handling of leading zeroes, and produces a result easier for humans to easily understand and do by hand.) Change all references to sorting to use version-sorting. Change all references to "ASCIIbetically" to instead say "sort non-lowercase before lowercase".
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".