rust-lang / rust-lang/rustfmt

Group use vs mod statements

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

Nobody has claimed this yet.

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

Description

Consider the following:

use std::borrow::Cow;
use std::alloc::GlobalAlloc;
pub mod baz;
use std::cell::Cell;
use std::ascii::AsciiExt;

When running rustfmt, this sorts the use statements alphabetically, but leaves the mod in place:

use std::alloc::GlobalAlloc;
use std::borrow::Cow;
pub mod baz;
use std::ascii::AsciiExt;
use std::cell::Cell;
  1. Is there an established convention for whether all mod statements should go above or below all use?
  2. If so, is there a way to enforce that in rustfmt?

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 running rustfmt on the Rust snippet in the issue and comparing how it orders the use and mod statements. Determine whether the project has an established ordering convention, then check whether rustfmt exposes a relevant configuration or entry point. Done means the convention is documented or the requested ordering can be consistently enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.