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

Rustfmt deletes comments in trait declarations #4672

Open
luliic2 opened this issue Jan 26, 2021 · 4 comments
Open

Rustfmt deletes comments in trait declarations #4672

luliic2 opened this issue Jan 26, 2021 · 4 comments
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-comments bug Panic, non-idempotency, invalid code, etc.

Comments

@luliic2
Copy link

luliic2 commented Jan 26, 2021

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
@luliic2 luliic2 added the bug Panic, non-idempotency, invalid code, etc. label Jan 26, 2021
@calebcartwright calebcartwright added 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-comments labels Jan 28, 2021
@karyon
Copy link
Contributor

karyon commented Oct 28, 2021

repro'd with 1.4.38

@ytmimi
Copy link
Contributor

ytmimi commented Apr 11, 2022

Just making a note that #4292 is the relevant backport PR, but #4213 is also related to comments and where clauses, and it might be nice to backport these together.

@ytmimi
Copy link
Contributor

ytmimi commented Apr 11, 2022

The issue also seems partially related to #4649, however #4649 also describes that comments are dropped between where clauses and function bodies.

@calebcartwright
Copy link
Member

The issue also seems partially related to #4649, however #4649 also describes that comments are dropped between where clauses and function bodies.

If there's a separate case that won't be covered by backporting a prior fix let's be sure to note that (preferably with a separate issue for tracking)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-comments bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

4 participants