Skip to content

Trailing comment unexpectedly removed when containing item is skipped #4028

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

Closed
carols10cents opened this issue Jan 24, 2020 · 0 comments · Fixed by #4297
Closed

Trailing comment unexpectedly removed when containing item is skipped #4028

carols10cents opened this issue Jan 24, 2020 · 0 comments · Fixed by #4297
Labels
a-comments a-rustfmt::skip bug Panic, non-idempotency, invalid code, etc.
Milestone

Comments

@carols10cents
Copy link
Member

Possibly related to #2781 and friends?

Versions

$ cargo +nightly --version
cargo 1.42.0-nightly (f6449ba23 2020-01-21)
$ rustc +nightly --version
rustc 1.42.0-nightly (41f41b2 2020-01-23)

What happened

I have these steps in a repo as well with commits for the different things I tried.

I have some weird comment placement that I'm trying to keep, so I want to skip formatting for them.

Here's the code with the weird comments:

fn myfunc1() {
    println!("hi");      // yes I want my comments here
}       // keep this comment here too

fn myfunc2() {
    println!("bye");        // i want it that way
}    // tell me why

The behavior I'm trying to get is something that doesn't change anything about these comments.

First, I tried skipping each of these functions, but running cargo +nightly fmt still changes the whitespace between the closing curly brackets of the functions and the start of the trailing comments, which isn't what I want:

#[rustfmt::skip]
fn myfunc1() {
    println!("hi");      // yes I want my comments here
} // keep this comment here too

#[rustfmt::skip]
fn myfunc2() {
    println!("bye");        // i want it that way
} // tell me why

So next, I tried changing the attribute to applying to the containing item instead, and this time the last comment gets completely removed:

#![rustfmt::skip]

fn myfunc1() {
    println!("hi");      // yes I want my comments here
}       // keep this comment here too

fn myfunc2() {
    println!("bye");        // i want it that way
}

I expected the last comment to stay there, just like the keep this comment here too comment was left alone. That seems like a bug :(

@carols10cents carols10cents added bug Panic, non-idempotency, invalid code, etc. a-comments a-rustfmt::skip labels Jan 24, 2020
tarcieri added a commit to RustCrypto/block-ciphers that referenced this issue Jun 3, 2020
It appears rustfmt strips all trailing comments:

rust-lang/rustfmt#4028
tarcieri added a commit to RustCrypto/block-ciphers that referenced this issue Jun 3, 2020
It appears rustfmt strips all trailing comments:

rust-lang/rustfmt#4028
tarcieri added a commit to RustCrypto/block-ciphers that referenced this issue Jun 3, 2020
It appears rustfmt strips all trailing comments:

rust-lang/rustfmt#4028
@topecongiro topecongiro added this to the 2.1.0 milestone Jun 29, 2020
topecongiro added a commit to topecongiro/rustfmt that referenced this issue Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-rustfmt::skip bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants