Skip to content

Commit d2e6f50

Browse files
anforowiczChromium LUCI CQ
authored andcommitted
[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 <[email protected]> Reviewed-by: Erik Staab <[email protected]> Reviewed-by: danakj <[email protected]> Cr-Commit-Position: refs/heads/main@{#927003}
1 parent 59a0e96 commit d2e6f50

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
*.mojom text eol=lf
2929
*.pdf -diff
3030
*.proto text eol=lf
31+
*.rs text eol=lf
3132
*.sh text eol=lf
3233
*.sql text eol=lf
34+
*.toml text eol=lf
3335
*.txt text eol=lf
3436
*.xml text eol=lf
3537
*.xslt text eol=lf

.rustfmt.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file defines the Rust style for automatic reformatting.
2+
# See also https://rust-lang.github.io/rustfmt
3+
4+
# Rust language edition to be used by the parser.
5+
edition = "2021"
6+
7+
# Version of the formatting rules to use.
8+
version = "Two"
9+
10+
# Line endings will be converted to \n.
11+
newline_style = "Unix"
12+
13+
# The "Default" setting has a heuristic which splits lines too aggresively.
14+
# We are willing to revisit this setting in future versions of rustfmt.
15+
# Bugs:
16+
# * https://github.com/rust-lang/rustfmt/issues/3119
17+
# * https://github.com/rust-lang/rustfmt/issues/3120
18+
use_small_heuristics = "Max"

OWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ per-file [email protected]
1515
1616
per-file .gn=file://build/OWNERS
1717
per-file .mailmap=*
18+
per-file .rustfmt.toml=file://styleguide/rust/OWNERS
1819
per-file .vpython*[email protected]
1920
per-file .vpython*[email protected]
2021
per-file .yapfignore=*

build/rust/tests/test_rust_source_set/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub extern "C" fn say_hello_from_cpp() {
1010
pub fn say_hello() {
1111
println!(
1212
"Hello, world - from a Rust library. Calculations suggest that 3+4={}",
13-
add_two_ints_via_rust(3, 4));
13+
add_two_ints_via_rust(3, 4)
14+
);
1415
}
1516

1617
#[test]

styleguide/rust/OWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TODO(danakj): We should consider having different style OWNERS from
2+
# code and toolchain OWNERS. OTOH, for now forwarding seems okay.
3+
file://build/rust/OWNERS

0 commit comments

Comments
 (0)