Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap_comments on/off have inconsistent trailing whitespace handling in code blocks #4251

Closed
cjhopman opened this issue Jun 10, 2020 · 0 comments · Fixed by #4304 · May be fixed by #5288
Closed

wrap_comments on/off have inconsistent trailing whitespace handling in code blocks #4251

cjhopman opened this issue Jun 10, 2020 · 0 comments · Fixed by #4304 · May be fixed by #5288
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Milestone

Comments

@cjhopman
Copy link

With wrap_comments = false, rustfmt enforces that an empty line at the beginning of a code block has no trailing whitespace. With wrap_comments = true, rustfmt enforces taht that same line has a single trailing space.

The formatting of wrap_comments=true should probably be an accepted formatting with wrap_comments=false.

Repro:

[0s]: buck$ cat rustfmt.toml
edition = "2018"
merge_imports = true
merge_derives = true
use_field_init_shorthand = true
use_try_shorthand = true
wrap_comments = true
[0s]: buck$ cat fmt.rs | tr " " "#"
//!#```
//!
//!#use#something;
//!#```
[0s]: buck$ rustfmt fmt.rs
[0s]: buck$ cat fmt.rs | tr " " "#"
//!#```
//!#
//!#use#something;
//!#```
[0s]: buck$ vim rustfmt.toml
[2s]: buck$ cat rustfmt.toml
edition = "2018"
merge_imports = true
merge_derives = true
use_field_init_shorthand = true
use_try_shorthand = true
[0s]: buck$ rustfmt --check fmt.rs
Diff in /Users/cjhopman/buck/fbcode/buck/fmt.rs at line 1:
 //! ```
-//!
+//!
 //! use something;
 //! ```
@calebcartwright calebcartwright added a-comments only-with-option requires a non-default option value to reproduce labels Jun 10, 2020
@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Jun 29, 2020
@topecongiro topecongiro added this to the 2.0.1 milestone Jun 29, 2020
ayazhafiz added a commit to ayazhafiz/rustfmt that referenced this issue Jul 2, 2020
Currently, the first line pushed in a code block is a comment line
delimiter that includes a trailing space, even if the content of that
line is empty. Later lines are handled correctly because their content
is checked before adding the comment line delimiter. So, just apply the
same logic as is done for later lines to the first line.

Closes rust-lang#4251
topecongiro pushed a commit that referenced this issue Jul 3, 2020
Currently, the first line pushed in a code block is a comment line
delimiter that includes a trailing space, even if the content of that
line is empty. Later lines are handled correctly because their content
is checked before adding the comment line delimiter. So, just apply the
same logic as is done for later lines to the first line.

Closes #4251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
3 participants