rust-lang / rust-lang/rustfmt

Wrapping long trailing comments

Open
#6,726 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-2024-style-edition A-comments C-discussion P-low UO-wrap_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

(from https://github.com/rust-lang/rustfmt/issues/5577#issuecomment-3539743489, sorry for the off-topic comment!)

Don't align unrelated trailing comments after items or at the end of blocks

https://github.com/rust-lang/rustfmt/issues/5577#issuecomment-1315302533

I got hit by this change. There are occasions where I do want to break a trailing comment into multiple lines. Now I can't do that because rustfmt no longer align them.

If the intention is stopping unrelated comments from being aligned, is there a way for me to indicate that those comments are indeed related?

but i want make this issue more general. right now, rustfmt is not able to wrap long trailing comments:

func(); // a really long explanation of what this function does and why it does it and why it should be called here and such and such.

desired behavior with wrap_comments=true:

func(); // a really long explanation of what this function
        // does and why it does it and why it should
        // be called here and such and such

actual behavior: nothing happens.

before style-edition=2024, i could still manually break the comment up and rustfmt will properly align the lines. after, i am no longer able to, since rustfmt will format it as:

func(); // a really long explanation of what this function
// does and why it does it and why it should
// be called here and such and such

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 issue with the trailing-comment example using wrap_comments=true, comparing the behavior before and after style-edition=2024. The work is done when long trailing comments wrap and manually split related trailing comments retain their indentation without aligning unrelated comments.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.