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
22chapter covers [ formatting] ( #formatting ) , [ coding for correctness] ( #cc ) ,
33[ using crates from crates.io] ( #cio ) , and some tips on
44[ structuring your PR for easy review] ( #er ) .
@@ -25,6 +25,7 @@ pass the <!-- date-check: nov 2022 --> `--edition=2021` argument yourself when c
2525` rustfmt ` directly.
2626
2727[ fmt ] : https://github.com/rust-dev-tools/fmt-rfcs
28+
2829[ `rustfmt` ] :https://github.com/rust-lang/rustfmt
2930
3031## Formatting C++ code
@@ -40,6 +41,26 @@ When modifying that code, use this command to format it:
4041This uses a pinned version of ` clang-format ` , to avoid relying on the local
4142environment.
4243
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+
4364<a id =" copyright " ></a >
4465
4566<!-- REUSE-IgnoreStart -->
@@ -84,7 +105,7 @@ Using `_` in a match is convenient, but it means that when new
84105variants are added to the enum, they may not get handled correctly.
85106Ask yourself: if a new variant were added to this enum, what's the
86107chance 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
88109exhaustive match. (The same advice applies to ` if let ` and `while
89110let`, which are effectively tests for a single variant.)
90111
@@ -124,7 +145,7 @@ See the [crates.io dependencies][crates] section.
124145# How to structure your PR
125146
126147How 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.
128149
129150** Isolate "pure refactorings" into their own commit.** For example, if
130151you rename a method, then put that rename into its own commit, along
@@ -165,4 +186,5 @@ to the compiler.
165186 crate-related, often the spelling is changed to ` krate ` .
166187
167188[ tcx ] : ./ty.md
189+
168190[ crates ] : ./crates-io.md
0 commit comments