Skip to content

trait bounds with comments are not formatted #2055

Description

@gnzlbg

This compiles file:

pub trait A {}
pub trait B {}
pub trait C {}

pub trait Foo:
// A and C
A + C
// and B
    + B
{}

but rustfmt formats it into this:

pub trait Foo: A + C + B // A and C
A
    + C
// and B
    + B {
}

try this live (just click on Format in the playground)

which fails to compile with:

   Compiling playground v0.0.1 (file:///playground)
error: expected one of `(`, `+`, `::`, `<`, `where`, or `{`, found `A`
 --> src/main.rs:6:1
  |
5 | trait Foo: A + C + B // A and C:
  |                     - expected one of `(`, `+`, `::`, `<`, `where`, or `{` here
6 | A + C
  | ^ unexpected token

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-poor-formattingIssue: poor formatting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions