rust-lang / rust-lang/rustfmt

Sort mod, use, pub use, const, static, type, and extern crate items at the top of files

Open
#4,741 0 comments 9 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

Rust source files typically have various items at the top of the file, including:

  • mod
  • use (pub use is often grouped together with mod)
  • extern crate (predominantly in Rust 2015)
  • type
  • const
  • static
  • macro_rules!

There's a lot of inconsistency about the order of these items, so it would be great to have a sensible system enforced by rustfmt.

Many of these items (mod, use, type, const, static) can be marked public, and mod statements can have their contents specified inline (mod module_name { /* items */ }). These factors should potentially influence the item order.

I am not sure if there has been research before about which order makes the most sense, or has the most adoption in the community. If there is, that could be a good starting point to decide on the rustfmt-enforced order.

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

No files, tests, or entry points are named. Start by researching community conventions for ordering mod, use, extern crate, type, const, static, and macro_rules! items, including visibility and inline modules; done means rustfmt applies an agreed, consistent order.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.