0

[rust] [chromium] Minimal rustfmt support for git cl format.

This CL supplements
https://crrev.com/c/chromium/tools/depot_tools/+/3054980 that added
minimal `rustfmt` support to `depot_tools` repo (e.g. to `git cl format`
and `git cl presubmit` commands).

This CL:
- Provides the baseline configuration for `rustfmt`: .rustfmt.toml
- Tells `git` and `rustfmt` that `.rs` files should have Unix line
  endings
- Fixes minor formatting issues that have crept into `.rs` files
  that have already landed in Chromium repo
- Does some other bookkeeping (e.g. providing //styleguide/rust/OWNERS
  for symmetry with how C++ style and the top-level .clang-tidy are
  managed)

Manual tests:

    Setup:
    - Edit .rs files under build/rust/tests
    - Temporarily change the top-level .rustfmt.toml to say:
          comment_width = 40
          wrap_comments = true
    Test:
    - Run `git cl format`
    Verified behavior:
    - New formatting style was applied to the edited .rs file.

Bug: 1231317
Change-Id: I006ed8065dbb0a212162337dc91310d149d38aeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3187872
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: Erik Staab <estaab@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#927003}
This commit is contained in:
Lukasz Anforowicz
2021-09-30 23:44:00 +00:00
committed by Chromium LUCI CQ
parent 59a0e967a8
commit d2e6f50a8a
5 changed files with 26 additions and 1 deletions
.gitattributes.rustfmt.tomlOWNERS
build/rust/tests/test_rust_source_set
styleguide/rust

2
.gitattributes vendored

@ -28,8 +28,10 @@
*.mojom text eol=lf
*.pdf -diff
*.proto text eol=lf
*.rs text eol=lf
*.sh text eol=lf
*.sql text eol=lf
*.toml text eol=lf
*.txt text eol=lf
*.xml text eol=lf
*.xslt text eol=lf

18
.rustfmt.toml Normal file

@ -0,0 +1,18 @@
# This file defines the Rust style for automatic reformatting.
# See also https://rust-lang.github.io/rustfmt
# Rust language edition to be used by the parser.
edition = "2021"
# Version of the formatting rules to use.
version = "Two"
# Line endings will be converted to \n.
newline_style = "Unix"
# The "Default" setting has a heuristic which splits lines too aggresively.
# We are willing to revisit this setting in future versions of rustfmt.
# Bugs:
# * https://github.com/rust-lang/rustfmt/issues/3119
# * https://github.com/rust-lang/rustfmt/issues/3120
use_small_heuristics = "Max"

1
OWNERS

@ -15,6 +15,7 @@ per-file .git-blame-ignore-revs=thakis@chromium.org
per-file .gn=estaab@chromium.org
per-file .gn=file://build/OWNERS
per-file .mailmap=*
per-file .rustfmt.toml=file://styleguide/rust/OWNERS
per-file .vpython*=dpranke@google.com
per-file .vpython*=iannucci@chromium.org
per-file .yapfignore=*

@ -10,7 +10,8 @@ pub extern "C" fn say_hello_from_cpp() {
pub fn say_hello() {
println!(
"Hello, world - from a Rust library. Calculations suggest that 3+4={}",
add_two_ints_via_rust(3, 4));
add_two_ints_via_rust(3, 4)
);
}
#[test]

3
styleguide/rust/OWNERS Normal file

@ -0,0 +1,3 @@
# TODO(danakj): We should consider having different style OWNERS from
# code and toolchain OWNERS. OTOH, for now forwarding seems okay.
file://build/rust/OWNERS