Skip to content

trait bounds with comments are not formatted #2055

@gnzlbg

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions