rust-lang / rust-lang/rust

Comments are being reordered by `-Zunpretty=normal`

Open
#157,054 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-pretty C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

After running rustc -Zunpretty=normal on a simple file (see below), I expected the output to match the original source code exactly.
However, a doc-comment and a regular comment were reordered in the output.
Is this expected behavior?

NB: If the // comment comes before the /// comment, then there is no reordering.

Original code:

/// comment 1
// comment 2
fn test() {}

Output of running rustc -Zunpretty=normal test.rs:

// comment 2
/// comment 1
fn test() {}
Meta

rustc --version --verbose:

rustc 1.98.0-nightly (57d06900f 2026-05-27)
binary: rustc
commit-hash: 57d06900fd7d9ee06d3a7f323bb77f17ab3cfaf8
commit-date: 2026-05-27
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6

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 reproducing the example with rustc -Zunpretty=normal and compare the input and output comment order. Then trace the compiler's pretty-printing and comment handling to determine whether the reordering is intended; done means the behavior is understood and covered by an appropriate regression test or documented as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.