Skip to content

Comment after associated type bound is incorrectly discarded #6815

@jieyouxu

Description

@jieyouxu

Summary

Forked out of #6234.

I tried to format this code:

trait Foo {
    type Bar: Baz1 // what
    ;
}

Expected behavior

I expected to see this happen:

  • Comment is preserved

Actual behavior

Instead, this happened:

  • Comment is removed
trait Foo {
    type Bar: Baz1;
}

Configuration

rustfmt cli options used (if applicable):

$ rustfmt repro.rs --check

rustfmt configuration file (e.g. rustfmt.toml, if applicable): N/A

Reproduction Steps

Trivial.

Meta

rustfmt --version:

rustfmt 1.8.0-stable (01f6ddf758 2026-02-11)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-type-boundsArea: associated type boundsA-commentsArea: commentsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-unexpectedly-removes-codeIssue: unexpectedly removes code that we should not be removing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions