Skip to content

Rustfmt deletes comments in trait declarations #4672

Open
@luliic2

Description

@luliic2

Describe the bug
I have the following piece of code:

pub trait Foo<'a, 'b>
where
    'a: 'b, // Some random comment
{
}

Which rustfmt reformats to:

pub trait Foo<'a, 'b>
where
    'a: 'b,
{
}

Deleting the comment

To Reproduce

Run cargo fmt with the first code block results in the second code block

Expected behavior

The comment should not be deleted

Meta

  • rustfmt version: rustfmt 1.4.25-stable. Reddit user u/m0rphism also reports it can be reproduced with rustfmt 1.4.9-nightly
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: cargo fmt & from vscode

Metadata

Metadata

Assignees

No one assigned

    Labels

    1x-backport:pendingFixed/resolved in source but not yet backported to a 1x branch and releasea-commentsbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions