1
- This file offers some tips on the coding conventions for rustc. This
1
+ This file offers some tips on the coding conventions for rustc. This
2
2
chapter covers [ formatting] ( #formatting ) , [ coding for correctness] ( #cc ) ,
3
3
[ using crates from crates.io] ( #cio ) , and some tips on
4
4
[ structuring your PR for easy review] ( #er ) .
@@ -25,6 +25,7 @@ pass the <!-- date-check: nov 2022 --> `--edition=2021` argument yourself when c
25
25
` rustfmt ` directly.
26
26
27
27
[ fmt ] : https://github.com/rust-dev-tools/fmt-rfcs
28
+
28
29
[ `rustfmt` ] :https://github.com/rust-lang/rustfmt
29
30
30
31
## Formatting C++ code
@@ -40,6 +41,26 @@ When modifying that code, use this command to format it:
40
41
This uses a pinned version of ` clang-format ` , to avoid relying on the local
41
42
environment.
42
43
44
+ ## Formatting and linting Python code
45
+
46
+ The Rust repository contains quite a lof of Python code. We try to keep
47
+ it both linted and formatted by the [ ruff] [ ruff ] tool.
48
+
49
+ When modifying Python code, use this command to format it:
50
+ ``` sh
51
+ ./x test tidy --extra-checks=py:fmt --bless
52
+ ```
53
+
54
+ and the following command to run lints:
55
+ ``` sh
56
+ ./x test tidy --extra-checks=py:lint
57
+ ```
58
+
59
+ This uses a pinned version of ` ruff ` , to avoid relying on the local
60
+ environment.
61
+
62
+ [ ruff ] : https://github.com/astral-sh/ruff
63
+
43
64
<a id =" copyright " ></a >
44
65
45
66
<!-- REUSE-IgnoreStart -->
@@ -84,7 +105,7 @@ Using `_` in a match is convenient, but it means that when new
84
105
variants are added to the enum, they may not get handled correctly.
85
106
Ask yourself: if a new variant were added to this enum, what's the
86
107
chance that it would want to use the ` _ ` code, versus having some
87
- other treatment? Unless the answer is "low", then prefer an
108
+ other treatment? Unless the answer is "low", then prefer an
88
109
exhaustive match. (The same advice applies to ` if let ` and `while
89
110
let`, which are effectively tests for a single variant.)
90
111
@@ -124,7 +145,7 @@ See the [crates.io dependencies][crates] section.
124
145
# How to structure your PR
125
146
126
147
How you prepare the commits in your PR can make a big difference for the
127
- reviewer. Here are some tips.
148
+ reviewer. Here are some tips.
128
149
129
150
** Isolate "pure refactorings" into their own commit.** For example, if
130
151
you rename a method, then put that rename into its own commit, along
@@ -165,4 +186,5 @@ to the compiler.
165
186
crate-related, often the spelling is changed to ` krate ` .
166
187
167
188
[ tcx ] : ./ty.md
189
+
168
190
[ crates ] : ./crates-io.md
0 commit comments