rust-lang / rust-lang/rustfmt

option to enforce ordering for attributes and doc comments

Open
#3,744 6 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

There are two orderings possible with items that have both attributes and doc comments

/// doc comment
#[attribute]
fn foo() {}

#[attribute]
/// doc comment
fn foo() {}

A random twitter poll that I cannot find anymore made it clear that option 1 is significantly more popular than option 2 and some people (myself included) would prefer if we just settled on one of these variants and consistently enforced that style.

The proposed feature is to add a check for items that have both a doc comment and attributes and to format them all consistently. There should be an option to select either style. I believe that the former should be the default setting.

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 locating rustfmt's handling of items with both attributes and doc comments, along with its existing configuration options and tests. Implement the proposed check with selectable ordering, using the preferred doc-comment-first style as the default; done means both variants are formatted consistently according to that option.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.