Skip to content
CAI
Software that uses CAICheck a score

rust-lang/rustfmt

69.7

Adequate · 29 September 2026

33.7k

lines of production code

Rust

primary language

2

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is rustfmt, a tool for formatting Rust source code to enforce consistent style. It provides a command-line interface and a Cargo subcommand to format files, check for diffs, and output structured reports for CI integration. The system supports configurable style editions, handles complex macro parsing, and includes utilities for comparing formatting outputs and applying changes across Git history.

How it got here

2015–2018 — CLI modernization and configuration expansion

44 changes.

This period focused on modernizing the rustfmt command-line interface and introducing a standalone cargo-fmt binary with improved logging and argument parsing. The project significantly expanded its configuration system to support Style Editions and added numerous formatting options, accompanied by extensive test coverage for these new features and edge cases.

2019–2021 — Style edition 2024 support and CI integration

54 changes.

This period focused on implementing and testing support for the Rust 2024 style edition, ensuring consistent formatting across 2015 and 2024 configurations for macros, comments, and complex types. It also introduced new structured output emitters for CI integration and refactored the parser to better handle conditional compilation macros like cfg\_if and cfg\_select.

2022–2026 — Style Edition 2024 test coverage and CI migration

48 changes.

This period focused on extensive test coverage for the new Style Edition 2024, verifying formatting behaviors for imports, modules, macros, and comments across edition boundaries. It also included the migration of CI infrastructure from shell scripts to Rust, introducing new tooling for build verification and integration testing.

Features

Add git-rustfmt utility for formatting Git history

A new \git-rustfmt\ tool is introduced to format Rust code across a specified number of recent Git commits. It integrates with the \rustfmt\_nightly\ library to apply formatting changes and uses the \tracing\ crate for logging, which is configured via the \RUSTFMT\_LOG\ environment variable. The tool supports a \-u\ flag to format uncommitted files and includes logic to prune \mod.rs\/\lib.rs\ files to avoid redundant formatting.

src/git-rustfmt · high confidence

Initial project scaffolding and documentation

The repository has been initialized with core project files, including the Apache 2.0 and MIT licenses, a Code of Conduct, and a design document outlining the tool's architecture. Comprehensive documentation has been added, including a configuration guide detailing available formatting options, a contributing guide with setup and testing instructions, and a README with quick-start and usage information. Additionally, standard development configuration files such as \.editorconfig\, \.gitattributes\, and \.gitignore\ have been created to enforce consistent coding standards and manage version control.

(repo-wide) · high confidence

Introduce \`cargo-fmt\` as a standalone binary with new CLI options

This change adds a new \src/cargo-fmt/main.rs\ file, creating a standalone \cargo fmt\ command-line tool. Users can now use flags such as \--check\ to verify formatting without modifying files, \--package\ (or \-p\) to target specific packages, and \--manifest-path\ to specify a custom \Cargo.toml\. The tool also respects the \RUSTFMT\ environment variable to locate the formatter and supports \--message-format\ for output styling. It replaces the previous internal implementation with a new structure using \clap\ for argument parsing.

src/cargo-fmt · high confidence

Introduce \`config\_type\` procedural macro for configuration enums

The new \config\_proc\_macro\ crate provides a \\#\[config\_type\]\ attribute that automatically implements \Display\, \FromStr\, \Serialize\, and \ConfigType\ traits for enums. This allows configuration options defined as enums to be parsed from strings, serialized to strings, and exposed via documentation hints, while supporting \doc\_hint\, \value\, and \unstable\_variant\ attributes to customize behavior and stability.

_config\_proc\macro/src · high confidence

Introduce check\_diff CLI tool for comparing rustfmt formatting outputs

Adds a new \check\_diff\ crate and CLI binary that compiles a specified rustfmt fork (source) against the latest main rustfmt (target) and compares their formatting results across a curated set of Rust ecosystem repositories. Users can configure the comparison via CLI arguments, including the source repository URL, feature branch, Rust edition, style edition, release channel (stable, beta, nightly), specific commit hash, custom rustfmt config options, and the number of worker threads for parallel checking. The tool clones the necessary repositories, builds both rustfmt versions, runs the formatter on each file, and reports any formatting diffs found, exiting with failure if differences are detected.

_check\diff/src · high confidence

Introduce rustfmt-format-diff utility for selective code formatting

A new \src/format-diff\ tool has been added to allow users to format only specific ranges within files based on a git diff. The utility reads a diff from standard input, identifies the affected files and line ranges, and invokes \rustfmt\ with the \--file-lines\ argument to apply formatting selectively. Users can control which files are processed using a custom regex filter (defaulting to \\*.rs\) and adjust path prefix skipping via the \-p\ flag. Logging is controlled via the \RUSTFMT\_LOG\ environment variable, and the specific \rustfmt\ binary to use can be specified via the \RUSTFMT\ environment variable.

src/format-diff · high confidence

New structured output emitters for CI and integration

The emitter module now includes dedicated output formats for machine-readable reporting and CI integration. A new Checkstyle emitter produces XML output compliant with the Checkstyle format, allowing integration with static analysis tools. A JSON emitter outputs structured data listing misformatted files and their specific line mismatches, enabling programmatic consumption of formatting results. Additionally, a ModifiedLines emitter provides a compact text representation of changes, and the existing Diff and Files emitters have been refined to better handle newline style conflicts and file writing with backups.

src/emitter · high confidence

Behavioural changes

2705 commits (371 fixes) modifying src

A change to existing behaviour in src — 2705 commits (371 fixs), 41 files.

src · medium confidence · unverified

CI scripts rewritten in Rust with new linting and integration checks

The CI automation scripts (previously shell-based) have been rewritten in Rust, introducing three new command-line tools: \build-and-test\ (which enforces \-D warnings\ via RUSTFLAGS and runs builds/tests with \--locked\), \clippy-config-check\ (which verifies that Clippy lint configurations are consistent across all Cargo.toml files), and \integration\ (which clones external repositories like cargo, crater, and bitflags to verify formatting and test stability). This change replaces the previous shell-based CI execution model with a structured Rust binary, ensuring stricter linting consistency and more robust integration testing.

ci · high confidence

Config system refactored to support Style Edition defaults

The configuration system has been restructured to allow formatting options to have different default values depending on the selected Style Edition (e.g., 2015, 2024, 2027). This is achieved by introducing a \StyleEditionDefault\ trait and a \style\_edition\_default!\ macro that map config options to edition-specific values, and by updating the \Config\ struct and its setter methods to resolve these defaults during initialization. This change enables the tool to apply edition-aware formatting rules automatically without requiring users to manually override every option.

src/config · high confidence

Improved parsing for cfg\_select!, cfg\_if!, lazy\_static!, and asm! macros

Rustfmt now includes dedicated parsers for several common macros, allowing it to understand and correctly format their internal structure. Specifically, it can now parse \cfg\_select!\ arms to discover modules defined within conditional compilation blocks, handle \cfg\_if!\ blocks to resolve module paths, format \lazy\_static!\ declarations, and process \asm!\ arguments. This change prevents infinite loops during \cfg\_select!\ parsing and ensures that items inside these macros are formatted consistently with the rest of the codebase.

src/parse/macros · high confidence

Parser module restructured with new session and builder patterns

The \src/parse\ module has been reorganized into \mod.rs\, \parser.rs\, and \session.rs\. The parser now uses a \ParserBuilder\ to construct \Parser\ instances, enforcing required inputs like \ParseSess\ and \Input\. A new \ParseSess\ wrapper manages the underlying rustc parse session, error handling via \SilentOnIgnoredFilesEmitter\, and module resolution logic, including a fallback to \dir\_path\ when relative external module resolution fails.

src/parse · high confidence

Refactor doc comment formatting logic

The logic for formatting doc comments has been refactored to use a new \DocCommentFormatter\ struct that processes string literals directly instead of using \Symbol\ values. This change improves the handling of multi-line doc attributes and ensures that empty doc attributes (\\#\[doc = ""\]\) are normalized correctly by inserting an empty line. The implementation now uses \peek()\ for safer iteration over lines, preserving whitespace within lines while correctly applying comment style openers.

src/attr · high confidence

Rustfmt binary rewritten with modern CLI and logging

The rustfmt command-line interface has been significantly restructured to improve usability and reliability. It now uses the \tracing\ ecosystem for logging, controlled via the \RUSTFMT\_LOG\ environment variable, replacing previous logging mechanisms. The CLI options have been consolidated and renamed: \--write-mode\ is replaced by \--emit\ (supporting modes like \files\, \stdout\, \coverage\, \checkstyle\, and \json\), and \--dump-default-config\/\--dump-minimal-config\ are replaced by \--print-config\ (supporting \default\, \minimal\, and \current\). A new \--check\ flag allows users to verify formatting without modifying files, exiting with code 1 if changes are needed. The \--style-edition\ option is now stable and allows specifying the style guide version (e.g., 2024). Additionally, \--backup\ is available to backup modified files, and \--files-with-diff\ (or \-l\) lists files that would be formatted. Error handling has been rationalized using \thiserror\, and the binary now exits with code 1 for license check failures in \--check\ mode and for general errors.

src/bin · high confidence

Support for @generated markers and improved Windows newline handling

Users can now skip formatting for files containing the \@generated\ marker by setting the new \generated\_marker\_line\_search\_limit\ configuration option, which controls how many lines are scanned for the marker. Additionally, the tool now more reliably detects and preserves Windows-style line endings (CRLF) in input files, including those with multibyte characters, and ensures that standalone carriage returns are handled correctly during conversion.

src/formatting · high confidence

Support for module discovery inside cfg\_if and cfg\_select macros

The module visitor now traverses \cfg\_if!\ and \cfg\_select!\ macro calls to discover nested module declarations, ensuring that modules defined within these conditional compilation blocks are correctly identified. Additionally, the \PathVisitor\ has been updated to handle Windows-specific path separators when extracting \path\ attributes from macro items.

src/modules · high confidence

Test coverage

Add tests for postfix-match syntax formatting; Added baseline tests for macro body width formatting; Added baseline tests for macro body widths; Added configuration option tests for rustfmt; Added configuration tests for brace styles and wildcard suffix condensing; Added idempotence and style-edition tests for single-line function formatting; Added idempotence test for non-mod.rs submodules; Added idempotence tests for loop and while formatting across Rust editions; Added import formatting tests; Added integration tests for cargo-fmt; Added integration tests for rustfmt command-line options; Added parser regression tests for various syntax and diagnostic edge cases; Added regression tests for cfg\_if macro formatting; Added regression tests for enum formatting edge cases; Added regression tests for format string handling; Added regression tests for import formatting (issue \#5852); Added regression tests for import granularity and formatting edge cases; Added regression tests for issue \#2482 regarding module reordering; Added regression tests for issue \#3779; Added regression tests for macro body formatting with comments; Added regression tests for macro formatting configurations; Added regression tests for macro rewriting with \asm!\ and \println!\; Added regression tests for module resolution fallback logic; Added regression tests for non-idempotent block doc comment formatting; Added regression tests for string formatting and whitespace handling; Added regression tests for struct field alignment and trailing comma formatting; Added regression tests for style edition formatting differences; Added regression tests for trailing comma handling in multi-line comments; Added run-time CPU feature detection tests for multiple architectures; Added smoke tests for the config\_proc\_macro; Added snapshot tests for formatting error warnings; Added style-edition-specific formatting tests for issue \#4689; Added test case for enum discriminant alignment threshold of 40; Added test cases for Block and Visual indent styles; Added test cases for Style Edition 2024 overflow delimiter expression handling; Added test cases for format\_macro\_bodies and format\_macro\_matchers configurations; Added test cases for function and item brace style configurations; Added test cases for import granularity and various formatting scenarios; Added test cases for imports\_layout configuration options; Added test cases for indent\_style configuration; Added test cases for itemized markdown lists in comments; Added test cases for module reordering with case-insensitive path handling; Added test cases for multiline generic bounds formatting; Added test cases for overflow\_delimited\_expr behavior in Rust 2015 and 2024 editions; Added test cases for rustfmt::skip behavior; Added test cases for struct field alignment threshold; Added test cases for struct field alignment threshold configuration; Added test cases for trailing comment formatting with hard and soft tabs; Added test coverage for configuration snippets, module resolution, and parser error handling; Added test coverage for for-loop pattern formatting with 'in' connectors; Added test coverage for inner module path resolution; Added test coverage for issue \#4656; Added test coverage for itemized markdown lists in comments; Added test coverage for long pattern matching in lint checks; Added test coverage for module resolution with rustfmt::skip; Added test coverage for packed\_simd From/Into implementations; Added test coverage for write modes and emit formats; Added test fixtures for issue \#4660 config path search behavior; Added test fixtures for nested module structures; Added test for macro comment formatting; Added test for macro rewriting of const items; Added test for mixed imports layout with crate granularity; Added test for module resolution with nested modules; Added test for nested out-of-line module resolution; Added test for nested parentheses removal in function calls; Added test for qualified path formatting in macros; Added test for qualified path retention in struct literals; Added test for single-line where clause formatting; Added test for trailing semicolon retention in issue 5797; Added test for variadic function parameter attribute preservation; Added tests for NonZero type import sorting across style editions; Added tests for arrow handling in comments with style\_edition 2024; Added tests for attribute inlining and import reordering; Added tests for attribute preservation in trait functions and variadic parameters; Added tests for binop\_separator = Back; Added tests for block comment formatting across style editions; Added tests for block trailing comma call formatting; Added tests for cfg\_attr module path formatting; Added tests for cfg\_select module discovery; Added tests for check\_diff functionality; Added tests for comment formatting in lists; Added tests for comment wrapping behavior; Added tests for comment wrapping in deeply nested and itemized blocks; Added tests for comment wrapping in lists; Added tests for complex function type formatting across style editions; Added tests for const generic default formatting; Added tests for derive attribute formatting with comments; Added tests for derive attribute merging and skip behavior; Added tests for doc comment code block formatting behavior; Added tests for doc comment code block width configuration; Added tests for file-lines configuration with CRLF and LF line endings; Added tests for file-lines range formatting; Added tests for formatting consistency of \assert!\ and \assert\ macros across style editions; Added tests for formatting function parameters with complex types; Added tests for generated file formatting and marker search limit; Added tests for impl generic indentation with style\_edition 2024; Added tests for import grouping and granularity configurations; Added tests for issue \#3665 regarding attribute skipping; Added tests for issue \#5801 regarding attribute and comment wrapping; Added tests for macro matcher formatting; Added tests for macro skip behavior in nested contexts; Added tests for markdown blockquote comment formatting; Added tests for markdown header handling in doc comments; Added tests for match arm attribute indentation across style editions; Added tests for module reordering across style editions; Added tests for module resolution error scenarios; Added tests for nested module and path attribute handling; Added tests for normalize\_doc\_attributes config; Added tests for out-of-line module resolution with conditional compilation; Added tests for path clarity in nested modules; Added tests for raw identifier import sorting across version gates; Added tests for rustfmt::skip attribute handling in modules; Added tests for spaces\_around\_ranges config in match patterns; Added tests for spacing around range expressions; Added tests for string formatting in macro definitions; Added tests for struct field alignment in block and visual styles; Added tests for struct field alignment in match patterns and enum variants; Added tests for struct pattern formatting with trailing commas; Added tests for style\_edition configuration derivation; Added tests for the reorder\_modules configuration option; Added tests for the use\_field\_init\_shorthand config option; Added tests for trace! macro formatting consistency; Added tests for trailing comma preservation in single-line macros; Added tests for trailing comment formatting with hard tabs; Added tests for trailing semicolon enforcement in loop bodies; Added tests for trailing semicolon formatting in match arms across style editions; Added tests for use\_small\_heuristics configuration options; Added tests for where-clause formatting in style edition 2024; Added unit tests for cargo-fmt argument parsing and target discovery.

Dependencies

Rustfmt 1.11.0 dependency update and lockfile generation

This change updates the Rustfmt project to version 1.11.0 and introduces Cargo.lock files for the main crate, the \check\_diff\ utility, the \config\_proc\_macro\ crate, and the CI integration tool. It upgrades key dependencies including \clap\ to 4.5, \itertools\ to 0.15, \toml\ to 1.1, and \annotate-snippets\ to 0.12, while also updating the \rustfmt-config\_proc\_macro\ to version 0.3.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 70 → 70 (-0.3)
  • Rubric changed (rubric-2026.09.9 → rubric-2026.09.18) — scores are not directly comparable.

Lenses

  • Code Health 78 → 79 (+0.2)
  • Architecture 100 → 94 (-6.2)
  • Maturity 65 → 65 (-0.0)
  • Readiness 68 → 67 (-1.5)
  • Security 70 → 76 (+6.0)
  • Performance 85 (new)

Resolved (12)

  • Documentation: no installation or build instructions (README.md)
  • Documentation: no usage examples (README.md)
  • Duplicated block (30 lines × 2) (src/items.rs)
  • FixmeComment (src/chains.rs)
  • FixmeComment (src/chains.rs)
  • Hotspot: src/comment.rs (src/comment.rs)
  • Hotspot: src/modules.rs (src/modules.rs)
  • Hotspot: src/parse/macros/mod.rs (src/parse/macros/mod.rs)
  • Hotspot: src/types.rs (src/types.rs)
  • Hotspot: src/visitor.rs (src/visitor.rs)
  • Off-boarding risk: anonymized user #1
  • Orphaned knowledge (src/lists.rs)

New (22)

  • Duplicated block (11 lines × 2) (src/items.rs)
  • Duplicated block (18 lines × 2) (src/items.rs)
  • FixmeComment (src/chains.rs)
  • Inconsistent naming pattern for equivalent operations. One method takes content directly, the other takes a path, but the naming convention does not clearly distinguish the input type (e.g., 'format' vs 'format_from_path'). This breaks the symmetry often seen in APIs where 'format' might imply string input and 'format_file' or similar implies path input, or vice versa.
  • Low cohesion: ListFormatting (LCOM4 6) (src/lists.rs)
  • Off-boarding risk: anonymized user #1
  • Outdated: anyhow
  • Outdated: clap
  • Outdated: diff
  • Outdated: getopts
  • Outdated: ignore
  • Outdated: proc-macro2
  • Outdated: quote
  • Outdated: regex
  • Outdated: serde
  • Outdated: serde_json
  • Outdated: tempfile
  • Outdated: toml
  • Outdated: tracing-subscriber
  • Outdated: unicode-properties
  • …and 2 more

Changes since last survey

  • 44 commits — 38 feature/other, 6 fixes

By area

  • (repo) — 16 commits
  • (root) — 8 commits
  • tests/source — 4 commits
  • src/chains.rs — 3 commits
  • .github/workflows — 2 commits
  • src/config — 2 commits
  • src/utils.rs — 2 commits
  • check_diff/Cargo.toml — 1 commit
  • ci/src — 1 commit
  • src/bin — 1 commit
  • src/imports.rs — 1 commit
  • src/lib.rs — 1 commit
  • tests/config — 1 commit
  • tests/parser — 1 commit

Notable commits

  • fix: Merge pull request #6396 from ding-young/fix-panic-on-enum
  • fix: Merge pull request #7115 from rami3l/fix/config-path-dirwalk
  • fix: fix panic on failure to format generics in enum
  • fix: fix(ci): also run clippy on check_diff
  • fix: fix(ci): use --locked for clippy-related inovcations
  • fix: fix(config): search for config file recursively on --config-path
  • change: Add clippy linting to all packages
  • change: Add some more chain comment tests
  • change: Auto merge of #162499 - GuillaumeGomez:subtree-update_cg_gcc_2026-09-08, r=antoyo
  • change: Avoid passing entire config to get_prefix_space_width
  • change: Initial josh-sync configuration
  • change: Introduce ast::UseTreeAndId
  • change: Merge commit '39f626bc72757517b75d8e2dde50fa832b8d6c03'
  • change: Merge pull request #6883 from matthewhughes934/hard-tabs-issue-6859
  • change: Merge pull request #7040 from jieyouxu/jieyouxu/ci/lock
  • change: Merge pull request #7095 from matthewhughes934/chain-refactor-2
  • change: Merge pull request #7116 from matthewhughes934/add-clippy-repeated-config
  • change: Merge pull request #7118 from matthewhughes934/chain-refactor-3
  • change: Merge pull request #7124 from rust-lang/ci-lock
  • change: Merge pull request #7127 from ytmimi/subtree-push-nightly-2026-09-21
  • …and 24 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

rust-lang/rustfmt was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 29 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit ec46636574fca6fce6014a143392f7d4a6d4d2ee — the exact code this score is about.
  • Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-c4983f2d4e5c.