diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 000000000000..2ecade5e9dfd --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,6 @@ +# Enable these if you want to run `cargo +nightly fmt`: +# group_imports = "StdExternalCrate" +# imports_granularity = "Module" + +# To apply these, uncomment the above lines, then run `cargo +nightly fmt`. +# Then comment them again, and run `pixi run codegen --force && pixi run codegen-protos && cargo fmt` diff --git a/CODE_STYLE.md b/CODE_STYLE.md index 7bad36a52f5d..e662e036c4a8 100644 --- a/CODE_STYLE.md +++ b/CODE_STYLE.md @@ -130,6 +130,10 @@ When importing a `trait` to use its trait methods, do this: `use Trait as _;`. T 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. +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). + +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. + ### `TODO`:s 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)`.