rust-lang / rust-lang/rustfmt

`wrap_comments` is not applied to code in doc comments

Open
#6,186 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments only-with-option UO-wrap_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Hello!

I just came across the wonderful (currently unstable) commands comment_width & wrap_comments which I happily applied to a larger codebase and thought this is the end to comments spanning longer then 100 in width. But to my surprise after pushing the change I noticed not all comments was formatted. It appears that code that is within a triple tick section done below will not be formatted.

/// ```rust
/// pub struct ImportantData {
///     // This text will however not be formatted to adhere to the max length of comments even tough it will end up on the doc page just like other comments.
///     some_field: u32,
/// }
/// ```

This ends up looking bad in the source code as well on the doc page. The output can be seen in the screenshot below.

image

Is this expected? If so is there a way around this limitation, I have looked at the available commands to rustfmt but haven't found anything.

I have put together a minimal example of the issue here

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 linked minimal example and reproduce the behavior using wrap_comments and comment_width. Trace how rustfmt handles fenced code in doc comments, then verify that comments inside the fence are wrapped consistently with other doc comments.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.