Skip to content

fix: preserve blank lines when removing empty statements consistently#6853

Open
utakotoba wants to merge 2 commits intorust-lang:mainfrom
utakotoba:fix/inconsistent-newline
Open

fix: preserve blank lines when removing empty statements consistently#6853
utakotoba wants to merge 2 commits intorust-lang:mainfrom
utakotoba:fix/inconsistent-newline

Conversation

@utakotoba
Copy link
Copy Markdown

fixes #6816

Summary

Fix formatting around empty statements (;) so removing them does not break surrounding blank lines or comment placement. Before this change, rustfmt could behave inconsistently when an empty statement appeared by itself or before a trailing comment (described in original issue).

Fix

Improved the handling of removed empty statements by preserving following same-line comments, aligning blank-line behavior with rustfmt's standard vertical spacing, avoiding incorrect comment recovery on stripped semicolons.

In practice, it is consistent for the following three cases:

  • if a line only contains a redundant ;, removes that line and lets normal newline handling apply
  • if a line is ; <comment>, removes only the redundant ; and keeps the comment correctly indented on its own line
  • surrounding blank lines respect the configured upper/lower bounds

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Apr 2, 2026
@utakotoba utakotoba marked this pull request as draft April 2, 2026 09:50
@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Apr 2, 2026
@utakotoba utakotoba marked this pull request as ready for review April 2, 2026 10:15
@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Apr 2, 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.

Newlines are (inconsistently) removed around lines with only semicolons

2 participants