Skip to content

fix: avoid leaking wrapper space from doc comment code block formatting#6851

Open
utakotoba wants to merge 2 commits intorust-lang:mainfrom
utakotoba:main
Open

fix: avoid leaking wrapper space from doc comment code block formatting#6851
utakotoba wants to merge 2 commits intorust-lang:mainfrom
utakotoba:main

Conversation

@utakotoba
Copy link
Copy Markdown

fixes #6832

Summary

Fixes a bug in doc comment code block formatting where rustfmt can introduce a trailing space and then report left behind trailing whitespace (if error_on_unformatted = true).

This happens with the following configuration:

format_code_in_doc_comments = true
fn_single_line = true

Fix

Handle the single-line wrapped case when extracting the formatted code block body so wrapper-added whitespace is not preserved in the returned snippet.

The current fix is narrowly scoped to catch only single-line functions in doc comments. A simpler solution would be to wrap the final result with remove_trailing_white_spaces(), but I don’t think it’s ideal since it would somehow impact more cases.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trailing space on doc comment

2 participants