rust-lang / rust-lang/rustfmt

Newlines are (inconsistently) removed around lines with only semicolons

Open
#6,816 3 comments 0 reactions 1 assignee View on GitHub

@caelyreth is already working on this.

Since Apr 2, 2026.

A-comments A-statements A-whitespace C-bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

The code:

fn a() {
    let v1 = 1;
    ;

    let v2 = 2;
}

fn b() {
    let v1 = 1;

    ;
    let v2 = 2;
}

fn c() {
    let v1 = 1;

    ; // comment
}

Output of rustfmt --check main.rs:

Diff in /tmp/main.rs:1:
 fn a() {
     let v1 = 1;
-    ;
 
     let v2 = 2;
 }
Diff in /tmp/main.rs:7:
 
 fn b() {
     let v1 = 1;
-
-    ;
     let v2 = 2;
 }
 
Diff in /tmp/main.rs:15:
 fn c() {
-    let v1 = 1;
-
-    ; // comment
+    let v1 = 1; // comment
 }

fn a is the expected case, in fn b an empty line is removed and in fn c the comment is placed on the same line as let v1 = 1; because there was a semicolon just before the start of the comment.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.