Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style-guide: clean up "must"/"should"/"may" #113380

Merged

Conversation

joshtriplett
Copy link
Member

@joshtriplett joshtriplett commented Jul 5, 2023

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.

Looking for "should"s also flagged some recommendations the style guide made
for configurability of tools (e.g. a tool "should" have a given configuration
option). I've removed those recommendations, per discussion with the style
team; it's not the domain of the style guide to make such recommendations, only
to define the default Rust style.

In the process of making this change, I also fixed a typo, fixed a text structure
issue, fixed an example that didn't match the Rust style (missing a trailing
comma), and added an additional example for clarity. (Those changes would have
conflicted with this one.) Those changes appear in separate commits.

These are all purely editorial changes, and do not affect the semantic
definition of the Rust style.

@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2023

r? @calebcartwright

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-style Relevant to the style team, which will review and decide on the PR/issue. labels Jul 5, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2023

Some changes occurred in src/doc/style-guide

cc @rust-lang/style

@joshtriplett joshtriplett force-pushed the style-guide-cleanup-must-should-may branch from 115324f to b58b979 Compare July 5, 2023 23:21
@bors
Copy link
Contributor

bors commented Jul 6, 2023

☔ The latest upstream changes (presumably #113391) made this pull request unmergeable. Please resolve the merge conflicts.

@joshtriplett joshtriplett force-pushed the style-guide-cleanup-must-should-may branch from f378942 to 9c1cc76 Compare July 11, 2023 20:26
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 14, 2023

☔ The latest upstream changes (presumably #113676) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM 👍

If you're good with removing the reorderable language in the derive section then feel free to r=me. Otherwise happy to talk about it.

The other comments are just thoughts/suggestions that I don't feel strongly about, and was even starting to second guess myself on things like "prefer" language

src/doc/style-guide/src/expressions.md Outdated Show resolved Hide resolved
src/doc/style-guide/src/README.md Outdated Show resolved Hide resolved
src/doc/style-guide/src/expressions.md Outdated Show resolved Hide resolved
src/doc/style-guide/src/expressions.md Outdated Show resolved Hide resolved
`* let` expressions and before `in` in a `for` expression; the following line
should be block indented. If the control line is broken for any reason, then the
opening brace should be on its own line and not indented. Examples:
If the control line needs to be broken, prefer to break before the `=` in `*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar thought as earlier wrt to "prefer", but don't feel strongly

Suggested change
If the control line needs to be broken, prefer to break before the `=` in `*
If the control line needs to be broken, break before the `=` in `*

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I think that this "prefer" represents "here's how to choose among multiple possible sources of line breaks". For instance, if you have to break it in another place because this break isn't sufficient, and with it broken in that other place you don't need to break before the =, then you shouldn't actually break it before the =.

If we want to say "always break before the = if you have to break at all, even if when done you don't need that break to stay under the line width", we could make this change, but I don't think that's accurate here?

Prefer not to line-break inside the discriminant expression. There must always
be a line break after the opening brace and before the closing brace. The match
arms must be block indented once:
Prefer not to line-break inside the discriminant expression. Always break after
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recognize this is another instance of existing "prefer" language. I don't think it's worth trying to change it now, but I'm curious how operative this really is. Whether the expression needs to be broken should be dependent on the respective rules for that expression, unless there's some match specific context carveout i'm nt familiar with

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebcartwright I think this is a semantically meaningful "prefer": if you need to break the line, and you have multiple places you could do so, try others first, and only break within the discriminant if nothing else suffices to get it below the line length.

src/doc/style-guide/src/expressions.md Show resolved Hide resolved
src/doc/style-guide/src/expressions.md Show resolved Hide resolved
src/doc/style-guide/src/expressions.md Show resolved Hide resolved
@joshtriplett joshtriplett force-pushed the style-guide-cleanup-must-should-may branch from f3e9370 to b763b4d Compare July 21, 2023 00:54
joshtriplett and others added 9 commits July 20, 2023 17:54
The style guide discusses the default Rust style. Configurability of
Rust formatting tools are not the domain of the style guide.
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.
…change)

Avoid putting a sentence fragment after a list; integrate it with the
sentence before the list.
…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.
Make it clear the rule for stacking the second line on the first applies
recursively, as long as the condition holds.
…rustfmt)

An example immediately following "Put each bound on its own line." did
not put each bound on its own line.
@joshtriplett
Copy link
Member Author

Fixed the reordering language, and address the comments. (Left two instances of "prefer" where I think they're accurately expressing a preference, made changes to address other comments.)

@bors r=calebcartwright

@bors
Copy link
Contributor

bors commented Jul 21, 2023

📌 Commit 77d09cb has been approved by calebcartwright

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2023
@joshtriplett
Copy link
Member Author

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 21, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#113380 (style-guide: clean up "must"/"should"/"may")
 - rust-lang#113723 (Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.)
 - rust-lang#113780 (Support `--print KIND=PATH` command line syntax)
 - rust-lang#113810 (Make {Rc,Arc}::allocator associated functions)
 - rust-lang#113907 (Minor improvements to Windows TLS dtors)

Failed merges:

 - rust-lang#113392 (style-guide: Some cleanups from the fmt-rfcs repo history)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 20ce7f1 into rust-lang:master Jul 21, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 21, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 1, 2023
…t, r=calebcartwright

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:

- rust-lang#113145
- rust-lang#113380
- rust-lang#113384
- rust-lang#113385
- rust-lang#113386
- rust-lang#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-style Relevant to the style team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants