rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Empty lines wrongly removed

Open jnqnfe opened this issue 4 years ago • 7 comments
trafficstars

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.

jnqnfe avatar Jul 30 '21 00:07 jnqnfe

Please provide your version of rustfmt, and the original, pre-formatted input along with, and separate from, the formatted result

calebcartwright avatar Aug 26 '21 03:08 calebcartwright

Please provide your version of rustfmt, and the original, pre-formatted input along with, and separate from, the formatted result

Please see #4928 regarding the version, and which also provides before and after copies of the code snippet applicable here.

jnqnfe avatar Aug 26 '21 20:08 jnqnfe

Updated with specific version string.

jnqnfe avatar Aug 29 '21 04:08 jnqnfe

Should this be closed @jnqnfe? It looks like the issue you linked has been closed.

stegaBOB avatar Jul 01 '22 00:07 stegaBOB

Should this be closed @jnqnfe? It looks like the issue you linked has been closed.

If you're referring to #4928, that isn't actually related at all so it's status doesn't have any impact on the status of this issue

calebcartwright avatar Jul 01 '22 02:07 calebcartwright

seems related to #3716

ytmimi avatar Jul 20 '22 19:07 ytmimi

rustfmt also removes blank lines at the end of the struct definition, between the last field and a comment, in the same way as this issue already describes for the beginning of the struct definition. That is,

struct Foo {
    // Introductory comment.
    
    /// Blah blah blah.
    foo: String,
    
    // Final comment.
}

is formatted as

struct Foo {
    // Introductory comment.
    /// Blah blah blah.
    foo: String,
    // Final comment.
}

and I think both blank lines should be preserved.

kpreid avatar Jul 18 '24 17:07 kpreid