Description
Describe the bug
When using comments within generic type parameters of a trait
, rustfmt corrupts the code as follows:
Input
pub trait Something<
A,
// some comment
B,
C
> {
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}
Output
pub trait Something<
A,
// some comment
B,
C,
> // some comment
B,
C
>
{
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}
The same applies for /* block comments */
:
Input
pub trait Something<
A,
/* some comment */
B,
C
> {
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}
Output
pub trait Something<A, /* some comment */ B, C> /* some comment */
B,
C
>
{
fn a(&self, x: A) -> i32;
fn b(&self, x: B) -> i32;
fn c(&self, x: C) -> i32;
}
However, this issue doesn't seem to appear for fn
s and struct
s.
To Reproduce
- Trait with single-line-comment (broken) - Playground
- Trait with block comment (broken) - Playground
- Struct with single-line-comment (not broken, just for comparison) - Playground
- Function with single-line-comment (not broken, just for comparison) - Playground
I ran rustfmt
without any parameters, so just rustfmt some-file-containing-the-example-above.rs
.
Expected behavior
I would expect the same formatting as for struct
s and fn
s (see the struct playground linked above).
Meta
- rustfmt version:
rustfmt 1.4.30-nightly (acd94866 2020-12-20)
- From where did you install rustfmt?: rustup (nightly toolchain)
- How do you run rustfmt:
rustfmt +nightly
Additional remarks
- I didn't find any existing issues matching this problem description, Const generic parameter following a comment gets corrupted #4263 looks a bit similar, though.
- Thank you all very much for maintaining this project, it's incredibly useful.
- I'm still a noob at writing rust, so I'm sorry if this is not actually a bug, but rather some mistake on my side.