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

Cfg block containing only a comment duplicates the previous lines. #4467

Closed
ExPixel opened this issue Oct 12, 2020 · 1 comment
Closed

Cfg block containing only a comment duplicates the previous lines. #4467

ExPixel opened this issue Oct 12, 2020 · 1 comment
Labels
bug Panic, non-idempotency, invalid code, etc. duplicate

Comments

@ExPixel
Copy link

ExPixel commented Oct 12, 2020

Describe the bug

Formatting an empty cfg block with a comment causes rustfmt to duplicate the cfg line.

pub fn main() {
    #[cfg(feature = "std")]
    {
        // Comment
    }
}

gets formatted into

pub fn main() {
    #[cfg(feature = "std")]
    {
        [cfg(feature = "std")]
    { // Comment
    }
}

Everything works as expected if there is actual code in the block or if the block is empty so the issue isn't too bad. Just thought it was worth mentioning.

To Reproduce
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=161085030374989f3243ad8eeb0328f5

Running rustfmt on the playground should display the weird behavior.

Expected behavior
I expect the output to just be

pub fn main() {
    #[cfg(feature = "std")]
    {
        // Comment
    }
}

Meta

  • rustfmt version: rustfmt 1.4.20-stable (48f6c32 2020-08-09)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: rustfmt in vim
@ExPixel ExPixel added the bug Panic, non-idempotency, invalid code, etc. label Oct 12, 2020
@ExPixel ExPixel changed the title Empty cfg block with comment duplicates line. Cfg block containing only a comment duplicates the previous lines. Oct 12, 2020
@calebcartwright
Copy link
Member

Thanks for the report @ExPixel

This is due to an upstream rustc bug that's subsequently been resolved, previously reported and discussed on the thread linked below. Closing as a duplicate, will go away after our next update.
#4452 (comment)
#4452 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. duplicate
Projects
None yet
Development

No branches or pull requests

2 participants