Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rustfmt and Formatting

Rule

Use the checked-in rustfmt.toml with pinned nightly-2026-04-14 as the formatting authority.

Why

A pinned formatter keeps editor, agent, local, and CI output reproducible when the project uses unstable rustfmt options.

Do

  • Keep rustfmt.toml at the workspace root.
  • Run cargo +nightly-2026-04-14 fmt --all before handing off Rust changes.
  • Run the same toolchain with --check in CI.
  • Let rustfmt decide layout.
  • Change formatter settings only in a focused formatting change.

Avoid

  • Do not mix stable, unpinned nightly, and the project pin.
  • Do not hand-format around rustfmt output.
  • Do not use #[rustfmt::skip] except for generated code or literals whose structure would become less readable.

Example

cargo +nightly-2026-04-14 fmt --all
cargo +nightly-2026-04-14 fmt --check --all

Exceptions

  • Existing projects may retain their current pin until a focused update.
  • Generated code may preserve generator-controlled layout.
  • Documentation snippets may use manual line breaks when rustfmt does not process them.