rust-lang / rust-lang/rustfmt

Comment before semicolon prevents formatting expression

Open
#5,535 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This code:

let     unformatted =    {     1}
// comment
;

or this:

let     unformatted =    {     1} // comment
;

will pass through rustfmt unchanged. Removing the comment causes the code to be formatted correctly, and other expressions are not affected.

You may be asking "why would anybody want to do this?" I keep a semicolon on its own line in a long chain of builder methods that I frequently have to modify, e.g.

builder
    .configure(cfg_fn1)
    .configure(cfg_fn2)
    // .configure(cfg_fn3)
    ;

Playground

Occurs in rustfmt 1.5.1-nightly (b44197a 2022-09-05) and rustfmt 1.5.1-stable (4b91a6e 2022-08-08).

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 with the minimal examples in the issue or the linked Rust Playground, using the reported rustfmt versions to reproduce the behavior. Trace how rustfmt handles a comment before a semicolon in an expression, then verify that both examples are formatted while the builder-chain case remains supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.