Skip to content

Commit f25e11a

Browse files
committed
sembr src/conventions.md
1 parent 41e0407 commit f25e11a

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

src/conventions.md

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Coding conventions
22

3-
This file offers some tips on the coding conventions for rustc. This
4-
chapter covers [formatting](#formatting), [coding for correctness](#cc),
5-
[using crates from crates.io](#cio), and some tips on
6-
[structuring your PR for easy review](#er).
3+
This file offers some tips on the coding conventions for rustc.
4+
This chapter covers [formatting](#formatting), [coding for correctness](#cc),
5+
[using crates from crates.io](#cio), and some tips on [structuring your PR for easy review](#er).
76

87
<a id="formatting"></a>
98

@@ -15,11 +14,11 @@ However, for now we don't use stable `rustfmt`; we use a pinned version with a
1514
special config, so this may result in different style from normal [`rustfmt`].
1615
Therefore, formatting this repository using `cargo fmt` is not recommended.
1716

18-
Instead, formatting should be done using `./x fmt`. It's a good habit to run
19-
`./x fmt` before every commit, as this reduces conflicts later.
17+
Instead, formatting should be done using `./x fmt`.
18+
It's a good habit to run `./x fmt` before every commit, as this reduces conflicts later.
2019

21-
Formatting is checked by the `tidy` script. It runs automatically when you do
22-
`./x test` and can be run in isolation with `./x fmt --check`.
20+
Formatting is checked by the `tidy` script.
21+
It runs automatically when you do `./x test` and can be run in isolation with `./x fmt --check`.
2322

2423
> **Note: Formatting and test suites**
2524
>
@@ -47,13 +46,12 @@ When modifying that code, use this command to format it:
4746
./x test tidy --extra-checks cpp:fmt --bless
4847
```
4948

50-
This uses a pinned version of `clang-format`, to avoid relying on the local
51-
environment.
49+
This uses a pinned version of `clang-format`, to avoid relying on the local environment.
5250

5351
### Formatting and linting Python code
5452

55-
The Rust repository contains quite a lot of Python code. We try to keep
56-
it both linted and formatted by the [ruff] tool.
53+
The Rust repository contains quite a lot of Python code.
54+
We try to keep it both linted and formatted by the [ruff] tool.
5755

5856
When modifying Python code, use this command to format it:
5957

@@ -78,17 +76,17 @@ These use a pinned version of `ruff`, to avoid relying on the local environment.
7876
### Copyright notice
7977
<!-- REUSE-IgnoreEnd -->
8078

81-
In the past, files began with a copyright and license notice. Please **omit**
82-
this notice for new files licensed under the standard terms (dual
79+
In the past, files began with a copyright and license notice.
80+
Please **omit** this notice for new files licensed under the standard terms (dual
8381
MIT/Apache-2.0).
8482

8583
All of the copyright notices should be gone by now, but if you come across one
8684
in the rust-lang/rust repo, feel free to open a PR to remove it.
8785

8886
### Line length
8987

90-
Lines should be at most 100 characters. It's even better if you can
91-
keep things to 80.
88+
Lines should be at most 100 characters.
89+
It's even better if you can keep things to 80.
9290

9391
Sometimes, and particularly for tests, it can be necessary to exempt yourself from this limit.
9492
In that case, you can add a comment towards the top of the file like so:
@@ -105,17 +103,15 @@ Prefer 4-space indents.
105103

106104
## Coding for correctness
107105

108-
Beyond formatting, there are a few other tips that are worth
109-
following.
106+
Beyond formatting, there are a few other tips that are worth following.
110107

111108
### Prefer exhaustive matches
112109

113110
Using `_` in a match is convenient, but it means that when new
114111
variants are added to the enum, they may not get handled correctly.
115112
Ask yourself: if a new variant were added to this enum, what's the
116-
chance that it would want to use the `_` code, versus having some
117-
other treatment? Unless the answer is "low", then prefer an
118-
exhaustive match.
113+
chance that it would want to use the `_` code, versus having some other treatment?
114+
Unless the answer is "low", then prefer an exhaustive match.
119115

120116
The same advice applies to `if let` and `while let`,
121117
which are effectively tests for a single variant.
@@ -155,41 +151,39 @@ See the [crates.io dependencies][crates] section.
155151

156152
## How to structure your PR
157153

158-
How you prepare the commits in your PR can make a big difference for the
159-
reviewer. Here are some tips.
154+
How you prepare the commits in your PR can make a big difference for the reviewer.
155+
Here are some tips.
160156

161157
**Isolate "pure refactorings" into their own commit.** For example, if
162158
you rename a method, then put that rename into its own commit, along
163159
with the renames of all the uses.
164160

165161
**More commits is usually better.** If you are doing a large change,
166-
it's almost always better to break it up into smaller steps that can
167-
be independently understood. The one thing to be aware of is that if
162+
it's almost always better to break it up into smaller steps that can be independently understood.
163+
The one thing to be aware of is that if
168164
you introduce some code following one strategy, then change it
169-
dramatically (versus adding to it) in a later commit, that
170-
'back-and-forth' can be confusing.
165+
dramatically (versus adding to it) in a later commit, that 'back-and-forth' can be confusing.
171166

172167
**Format liberally.** While only the final commit of a PR must be correctly
173168
formatted, it is both easier to review and less noisy to format each commit
174169
individually using `./x fmt`.
175170

176-
**No merges.** We do not allow merge commits into our history, other
177-
than those by bors. If you get a merge conflict, rebase instead via a
171+
**No merges.** We do not allow merge commits into our history, other than those by bors.
172+
If you get a merge conflict, rebase instead via a
178173
command like `git rebase --interactive rust-lang/main` (presuming you use the
179174
name `rust-lang` for your remote).
180175

181176
**Individual commits do not have to build (but it's nice).** We do not
182177
require that every intermediate commit successfully builds – we only
183-
expect to be able to bisect at a PR level. However, if you *can* make
184-
individual commits build, that is always helpful.
178+
expect to be able to bisect at a PR level.
179+
However, if you *can* make individual commits build, that is always helpful.
185180

186181
## Naming conventions
187182

188-
Apart from normal Rust style/naming conventions, there are also some specific
189-
to the compiler.
183+
Apart from normal Rust style/naming conventions, there are also some specific to the compiler.
190184

191-
- `cx` tends to be short for "context" and is often used as a suffix. For
192-
example, `tcx` is a common name for the [Typing Context][tcx].
185+
- `cx` tends to be short for "context" and is often used as a suffix.
186+
For example, `tcx` is a common name for the [Typing Context][tcx].
193187

194188
- [`'tcx`][tcx] is used as the lifetime name for the Typing Context.
195189

0 commit comments

Comments
 (0)