Skip to content

Commit ce5aca9

Browse files
committed
style-guide: Avoid using "should" or "may" for required parts of the default 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.
1 parent 081e15a commit ce5aca9

File tree

5 files changed

+252
-220
lines changed

5 files changed

+252
-220
lines changed

src/doc/style-guide/src/README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ example) and less rightward drift.
6262

6363
### Trailing commas
6464

65-
Lists should have a trailing comma when followed by a newline:
65+
In comma-separated lists of any kind, use a trailing comma when followed by a
66+
newline:
6667

6768
```rust
6869
function_call(
@@ -111,17 +112,17 @@ formatter might skip formatting of comments.
111112

112113
Prefer line comments (`//`) to block comments (`/* ... */`).
113114

114-
When using line comments there should be a single space after the opening sigil.
115+
When using line comments, put a single space after the opening sigil.
115116

116-
When using single-line block comments there should be a single space after the
117-
opening sigil and before the closing sigil. Multi-line block comments should
118-
have a newline after the opening sigil and before the closing sigil.
117+
When using single-line block comments, put a single space after the opening
118+
sigil and before the closing sigil. For multi-line block comments, put a
119+
newline after the opening sigil, and a newline before the closing sigil.
119120

120-
Prefer to put a comment on its own line. Where a comment follows code, there
121-
should be a single space before it. Where a block comment is inline, there
122-
should be surrounding whitespace as if it were an identifier or keyword. There
123-
should be no trailing whitespace after a comment or at the end of any line in a
124-
multi-line comment. Examples:
121+
Prefer to put a comment on its own line. Where a comment follows code, put a
122+
single space before it. Where a block comment appears inline, use surrounding
123+
whitespace as if it were an identifier or keyword. Do not include trailing
124+
whitespace after a comment or at the end of any line in a multi-line comment.
125+
Examples:
125126

126127
```rust
127128
// A comment on an item.
@@ -170,7 +171,7 @@ Prefer line comments (`///`) to block comments (`/** ... */`).
170171
Prefer outer doc comments (`///` or `/** ... */`), only use inner doc comments
171172
(`//!` and `/*! ... */`) to write module-level or crate-level documentation.
172173

173-
Doc comments should come before attributes.
174+
Put doc comments before attributes.
174175

175176
### Attributes
176177

@@ -195,18 +196,20 @@ struct CRepr {
195196
}
196197
```
197198

198-
For attributes with an equal sign, there should be a single space before and
199-
after the `=`, e.g., `#[foo = 42]`.
199+
For attributes with an equal sign, put a single space before and after the `=`,
200+
e.g., `#[foo = 42]`.
200201

201202
There must only be a single `derive` attribute. Note for tool authors: if
202203
combining multiple `derive` attributes into a single attribute, the ordering of
203-
the derived names should be preserved. E.g., `#[derive(bar)] #[derive(foo)]
204-
struct Baz;` should be formatted to `#[derive(bar, foo)] struct Baz;`.
204+
the derived names must generally be preserved for correctness:
205+
`#[derive(Foo)] #[derive(Bar)] struct Baz;` must be formatted to
206+
`#[derive(Foo, Bar)] struct Baz;`.
205207

206208
### *small* items
207209

208-
In many places in this guide we specify that a formatter may format an item
209-
differently if it is *small*, for example struct literals:
210+
In many places in this guide we specify formatting that depends on a code
211+
construct being *small*. For example, single-line vs multi-line struct
212+
literals:
210213

211214
```rust
212215
// Normal formatting
@@ -215,7 +218,7 @@ Foo {
215218
f2: another_expression(),
216219
}
217220

218-
// *small* formatting
221+
// "small" formatting
219222
Foo { f1, f2 }
220223
```
221224

0 commit comments

Comments
 (0)