rust-lang / rust-lang/rustfmt

[Feature Request] configure blank lines between related items

Open
#6,803 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-whitespace 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/3382

I'd like to request an option to specify the amount of blank lines between related items.

Related items either share the same concrete Type:

  • struct A
  • enum A
  • impl A
  • impl<T> A
  • impl Trait for A

Or the same Trait type:

  • trait T
  • impl T for A

Formatting rule

  • Between items in the same group: N blank lines. (default to 0 or 1)
  • Between different groups: exactly M blank lines (typically 1).

Example normalization (N = 0, M = 1):

struct A;
impl A {
  //...
}

struct B;
impl B {
  //...
};

Example configuration could be

top_level_items_related_blank_lines = 0
top_level_items_unrelated_blank_lines = 1

Inferring macros would be out of scope.

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 by reading the related rustfmt issue #3382 and the requested grouping examples. Define how related top-level items are identified, how the two blank-line configuration options interact, and what defaults apply. Done means rustfmt consistently separates related and unrelated items as specified, without requiring macro inference.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.