rust-lang / rust-lang/rustfmt

Allow per-item configuration

Open
#4,083 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Related to https://github.com/rust-lang/rustfmt/issues/3989#issuecomment-570737505.

Rationale: I have some code that looks like

enum InternalDeclarator {
    Id(InternedStr),
    Pointer { qualifiers: Vec<DeclarationSpecifier> },
    Array { size: Option<Box<Expr>> },
    // TODO: support abstract parameters
    Function { params: Vec<(TypeName, InternedStr)>, varargs: bool },
}

I'd like it to stay the same (i.e. all on one line) by setting use_small_heuristics = "Max". However, that changes all the code in the rest of the repository as well. Right now, I'm just using #[rustfmt::skip]. Could rustfmt add a way to set this for individual items (or even variants)?

I was imagining it would look something like this:

#[rustfmt::use_small_heuristics = "Max"]
enum InternalDeclarator {
    Id(InternedStr),
    Pointer { qualifiers: Vec<DeclarationSpecifier> },
    Array { size: Option<Box<Expr>> },
    // TODO: support abstract parameters
    Function { params: Vec<(TypeName, InternedStr)>, varargs: bool },
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the related discussion at rust-lang/rustfmt#3989 and compare the requested per-item setting with the existing #[rustfmt::skip] approach and the global use_small_heuristics = "Max" setting. The scope needs to settle whether attributes apply to items, variants, or both; done means a defined and implemented way to override the heuristic locally without changing unrelated code.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.