rust-lang / rust-lang/rustfmt

Empty lines wrongly removed

Open
#4,930 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The empty line after the initial comment within the struct definition here is there deliberately to separate it from the comments associated with the first attribute. rustfmt should not remove it, just as it preserves the choice I made to have empty lines between attributes for this struct.

 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
 pub struct TimingInfo {
     /* NOTE: This struct must be directly usable by the C API, thus same attributes/layout/etc */
-
     /// The system clock time when this timing info structure was current.
     pub timestamp: Timeval,
 
     /// Non-zero if the local and the remote machine have synchronized clocks. If synchronized
     /// clocks are detected `transport_usec` becomes much more reliable. However, the code that
     /// detects synchronized clocks is very limited and unreliable itself.
     pub synchronized_clocks: i32,
 
     /// Time in usecs a sample takes to be played on the sink. For playback streams and record
     /// streams connected to a monitor source.
     pub sink_usec: MicroSeconds,

config:

brace_style = "SameLineWhere"
comment_width = 100
control_brace_style = "ClosingNextLine"
edition = "2018"
fn_args_layout = "Compressed"
hard_tabs = false
match_block_trailing_comma = true
max_width = 100
merge_derives = false
newline_style = "Unix"
normalize_doc_attributes = true
overflow_delimited_expr = true
reorder_imports = false
group_imports = "StdExternalCrate"
reorder_modules = true
#struct_field_align_threshold = 20
tab_spaces = 4
trailing_comma = "Never"
use_small_heuristics = "Max"
use_try_shorthand = true
#where_single_line = true
wrap_comments = true

Version string: rustfmt 1.4.37-stable (a178d03 2021-07-26)
Project: https://github.com/jnqnfe/pulse-binding-rust
Specific file: https://github.com/jnqnfe/pulse-binding-rust/blob/master/pulse-binding/src/def.rs
Ran against the master branch after adding the quoted config.

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

Reproduce the issue with pulse-binding/src/def.rs from the linked pulse-binding project using the quoted rustfmt configuration and compare the formatted output with the deliberate blank line shown. Trace the formatter behavior responsible for removing that line, and consider the issue complete when the blank line is preserved without changing the existing spacing between attributes.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.