Skip to content

Newlines are (inconsistently) removed around lines with only semicolons #6816

@antonilol

Description

@antonilol

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.

Metadata

Metadata

Assignees

Labels

A-commentsArea: commentsA-statementsArea: statementsA-whitespaceArea: whitespace and its handlingC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions