Skip to content

Commit 1e44c8e

Browse files
authored
Codify how to group our imports (#12063)
I'll actually apply it once these PRs are merged: * #12044 * #12047 * #12048
1 parent 9ca7225 commit 1e44c8e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

.rustfmt.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Enable these if you want to run `cargo +nightly fmt`:
2+
# group_imports = "StdExternalCrate"
3+
# imports_granularity = "Module"
4+
5+
# To apply these, uncomment the above lines, then run `cargo +nightly fmt`.
6+
# Then comment them again, and run `pixi run codegen --force && pixi run codegen-protos && cargo fmt`

CODE_STYLE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ When importing a `trait` to use its trait methods, do this: `use Trait as _;`. T
130130

131131
When intentionally ignoring a `Result`, prefer `foo().ok();` over `let _ = foo();`. The former shows what is happening, and will fail to compile if `foo`:s return type ever changes.
132132

133+
We group and order imports (`use` statements) by `std`, other crates, and lastly own `crate` and `super`. This corresponds to [`StdExternalCrate`](https://rust-lang.github.io/rustfmt/?version=v1.8.0&search=group#StdExternalCrate%5C%3A).
134+
135+
We group our `use` statements by module, e.g. `crate_name::module::{a, b, c}`. This is a compromise, being rather terse while still avoiding excessive merge conflicts. See [the cargofmt docs](https://rust-lang.github.io/rustfmt/?version=v1.8.0&search=group#Module%5C%3A) for details.
136+
133137
### `TODO`:s
134138
When you must remember to do something before merging a PR, write `TODO` or `FIXME` in any file. The CI will not be green until you either remove them or rewrite them as `TODO(yourname)`.
135139

0 commit comments

Comments
 (0)