rustfmt
inconsistently formats blank lines in the beginning of blocks
#5361
Labels
rustfmt
inconsistently formats blank lines in the beginning of blocks
#5361
Description
The current implementation exhibits inconsistent behavior for blank lines in the beginning of blocks depending on the type of the block.
The formatter removes all blank lines in the beginning of
enum
,union
,struct
,impl
andtrait
.However, blank lines in
fn
s are trimmed and inserted to match the number of blank lines toblank_lines_lower_bound
.In
mod
andextern
, blank lines are clamped according toblank_lines_lower_bound
andblank_lines_upper_bound
.This mismatch appears very strange with custom
blank_lines_*_bound
values, but even with default values it seems weird.From the document on
blank_lines_lower_bound
in Configurations.md, the number of blank lines should be decided according to theblank_lines_*_bound
options.This matches to the current behavior for
mod
andextern
.On the other hand, some discussions in #2954 and #3382 concluded those options should not affect on it.
This matches to the current behavior for
enum
,union
,struct
,impl
andtrait
.#4295 tried to fix the v2 code, but it is not yet back-ported and still has some bugs like one reported in #5067.
Environment
version:
rustfmt 1.4.38-nightly (3e38399e 2022-05-26)
Sample
Source
Expected
Actual
Actual (with
blank_lines_lower_bound=1,blank_lines_upper_bound=2
)The
extern
block has an extra blank line in the end of the block, but this is a separate issue?The text was updated successfully, but these errors were encountered: