Re: [PATCH 2/6] ci: check formatting of our Rust code
- From
- Eric Sunshine <ericsunshine@gmail.com>
- Date
- Oct 7, 2025, 17:13 UTC
- Message-ID
- <CAPig+cQ7xJky+F=g=NMrN6BQfP+ZV2KF4RF2eLqtULKgMTR5_g@mail.gmail.com>
- In-Reply-To
- <20251007-b4-pks-ci-rust-v1-2-394502abe7ea@pks.im>
On Tue, Oct 7, 2025 at 8:37 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 14 quoted lines
> Introduce a CI check that verifies that our Rust code is well-formatted. > This check uses rustfmt(1), which is the de-facto standard in the Rust > world. > > The rustfmt(1) tool allows to tweak the final format in theory. In > practice though, the Rust ecosystem has aligned on style "editions". > These editions only exist to ensure that any potential changes to the > style don't cause reformats to existing code bases. Other than that, > most Rust projects out there accept this default style of a specific > edition. > > Let's do the same and use that default style. It may not be anyone's > favorite, but it is consistent and by making it part of our CI we also > enforce it right from the start.
In a different thread, I wrote[1]:
There are more than a few developers on this project (including
myself) who still use 80-column editors and terminals. As a
general style guideline, this project does recommend wrapping code
to fit within 80 columns (except in cases when doing so would
severely hurt readability). I imagine that the same sort of
guideline would be appreciated in Rust code, as well, by those who
still stick with 80 columns. I bring this up because, although it hasn't been such a big deal
with the existing C code, assuming that developers run `rustfmt`
on the code before sending a patch series, then this may become an
issue if different developers have `rustfmt` configured to enforce
different maximum column width, especially since `rustfmt` is
likely to reformat the entire file rather than just the region
that has just been edited. So, if this code gets checked in as-is
with these very wide lines, and then someone else, who has
`rustfmt` configured for 80-columns edits the file, then it
becomes a problem. As such, can we also add a project-wide `rustfmt.toml` which, at
minimum, sets the maximum line width to 80? For instance:max_width = 80
Later in the same thread, I wrote[2]:
Project guidelines have long suggested 80 columns as a desirable
maximum not only for C code, but for pretty much all other
resources, including shell code, Perl code, and documentation
files. This suggested maximum works well for adherents of
80-columns and (presumably) hasn't been too onerous for developers
who use wider windows; at least we haven't heard people clamoring
to increase the suggested maximum column limit. As such, it does
not seem far-fetched to expect that the project guidelines
should/could/would also apply to Rust code.Unfortunately, what little discussion there was petered out quickly without resolution, but it seems that it would be a good idea to make some sort of decision earlier (while there is still very little Rust code committed to the project) rather than later.
[1]: https://lore.kernel.org/git/CAPig+cTZch_pvfurtjBTNphMeRQL6jSBSjNY-4mffjoXZ4eqcw@mail.gmail.com/ [2]: https://lore.kernel.org/git/CAPig+cTdJAjuekz6YXDkxTjTRxsPEzSUxhoD8nK9k7uA4s=rHQ@mail.gmail.com/
> Signed-off-by: Patrick Steinhardt <ps@pks.im>