rustfmt
rust-lang.github.io
What it is
rustfmt formats Rust code according to style guidelines. It can format files directly or read code from standard input and write formatted output to standard output. With Cargo, `cargo fmt` formats binary and library targets in a crate and works with workspaces. A `rustfmt.toml` or `.rustfmt.toml` file can hold configuration, including stable and nightly-only options. For automated checks, `--check` returns code 0 when no formatting changes are needed and code 1 when changes would be made; it can be used in CI to fail a build on formatting differences. The README lists editor use with Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, IntelliJ, and CLion. Rustfmt is available on Windows, macOS, and Linux, and is distributed under the MIT License and Apache License 2.0. It does not attempt to format comments, and listed limitations also involve macros, unparsable code, fragments, and non-ASCII Unicode. Unstable settings require opt-in on nightly, and the README says the latest version requires the nightly toolchain.
Spec sheet
- Purpose
- rustfmt formats Rust code according to style guidelines.Read 3 Oct 2026 · github.com
- Support
- The README points users to `rustfmt --help` and `cargo fmt --help` for command usage and arguments.Read 3 Oct 2026 · github.com
- License
- rustfmt is distributed under both the MIT License and Apache License 2.0.Read 3 Oct 2026 · github.com
- Cargo
- The `cargo fmt` command formats binary and library targets in a crate and works with Cargo workspaces.Read 3 Oct 2026 · github.com
- Check mode
- With `--check`, rustfmt exits with code 0 when no formatting changes are needed and 1 when changes would be made.Read 3 Oct 2026 · github.com
- CI
- The README describes using `cargo fmt --all -- --check` to fail a CI build when code is not formatted.Read 3 Oct 2026 · github.com
- CI use
- The README describes using `--check` in CI to report formatting differences through an error code.Read 2 Oct 2026 · github.com
- Configuration
- Configuration can be set in `rustfmt.toml` or `.rustfmt.toml`, and the default style conforms to the Rust style guide.Read 3 Oct 2026 · github.com
- Direct use
- The rustfmt binary formats files in place or reads Rust code from standard input and writes formatted code to standard output.Read 3 Oct 2026 · github.com
- Editor integrations
- The README lists integrations or usage instructions for Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, and IntelliJ or CLion.Read 3 Oct 2026 · github.com
- Input and output
- The rustfmt binary can format files or read Rust code from standard input and write formatted output to standard output.Read 2 Oct 2026 · github.com
- Install
- The README installs rustfmt as a component through rustup.Read 3 Oct 2026 · github.com
- IntelliJ and CLion
- The IntelliJ and CLion instructions describe enabling rustfmt on save or assigning a shortcut to reformat a file.Read 3 Oct 2026 · github.com
- Limit: comments
- Rustfmt does not currently attempt to format comments, though it formats code that contains comments.Read 2 Oct 2026 · github.com
- Limit: macros
- The README says some macro declarations and uses are formatted, while macro declarations and uses are listed among rustfmt’s limitations.Read 2 Oct 2026 · github.com
- Limitations
- The README lists limitations involving unparsable code, macros, comments, code fragments, non-ASCII Unicode, and bugs.Read 3 Oct 2026 · github.com
- Nightly options
- The README marks coverage, checkstyle, and JSON emit formats as nightly-only options.Read 3 Oct 2026 · github.com
- Security contact
- The Rust Security Response Working Group handles vulnerability reports and security issues for rust-lang organization repositories.Read 2 Oct 2026 · github.com
- Style stability
- The Rust Edition Guide describes a formatting stability guarantee intended to avoid noisy formatting changes when updating the Rust toolchain.Read 2 Oct 2026 · doc.rust-lang.org
- Toolchains
- The README says rustfmt runs with Rust 1.24 and above, while the latest version requires the nightly toolchain.Read 3 Oct 2026 · github.com
Plans and prices
Strong points and limits
Strong points
- Formats Cargo crates and workspaces.
- Check mode can flag formatting differences in CI.
- Configuration supports stable and nightly-only options.
- Available for Windows, macOS, and Linux.
Limits
- Does not attempt to format comments.
- Unstable options require nightly and opt-in.
- Latest version requires the nightly toolchain.
- Limitations include macros and unparsable code.
Who it suits
rustfmt suits Rust developers who want consistent formatting in a crate or workspace, including teams that check formatting in CI. It also supports users who run formatting from listed editors.
Verdict
rustfmt provides command-line, Cargo, editor, and CI workflows for formatting Rust. Its comment and macro limitations, along with nightly requirements for some capabilities, are worth considering.
Where Specifiction places it
- Code Formatting Tools#10 of 348.0