rust-lang / rust-lang/rustfmt

Inconsistent Struct Body Opening Brace Placement After Where Clause

Open
#5,507 5 comments 0 reactions 1 assignee View on GitHub

@jmj0502 is already working on this.

Since Aug 18, 2022.

I-poor-formatting
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

When the body of a struct is empty or it only contains comments, the opening brace of the struct body is placed on the same line as the where clause. If the struct body is not empty, the opening brace is placed on a newline.

No configuration values are needed, and I was using rustfmt 1.5.1-nightly (841b4542 2022-08-17) when I came across this.

Input

struct EmptyBody<T>
    where T: Eq {
}

struct LineComment<T>
    where T: Eq {
    // body
}

struct BlockComment<T>
    where T: Eq {
    /* block comment */
}

struct HasBody<T>
    where T: Eq {
    x: T
}

Output

struct EmptyBody<T>
where
    T: Eq, {}

struct LineComment<T>
where
    T: Eq, {
    // body
}

struct BlockComment<T>
where
    T: Eq, {/* block comment */}

struct HasBody<T>
where
    T: Eq,
{
    x: T,
}

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.