PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: rust-lang/rustfmt (rust)

Issue:
/* comment */ inside trait generics gets duplicated
```rust
trait Test</* comment */ T> {}
```

Gets reformatted as

```rust
trait Test</* comment */ T> /* comment */ T> {}
```

Whereas no changes were expected.

Playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=88c36ba8a83e2c01030bbbf95327be6a

Setting `version = Two` has no effect.

```
λ rustfmt --version
rustfmt 1.4.38-stable (7737e0b 2022-04-04)
```

Pull request:
Fix/comments inside trait generics gets duplicated
# Fixes #5358 
* Now the value of `comment_hi` is equals to the `generic.span.lo` if there actually are any generic parameters, otherwise it will kept the value previously defined.

Patch:
diff --git a/src/items.rs b/src/items.rs
index 6ab02e7f..a76e88b7 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1084,7 +1084,11 @@ pub(crate) fn format_trait(
             let item_snippet = context.snippet(item.span);
             if let Some(lo) = item_snippet.find('/') {
                 // 1 = `{`
-                let comment_hi = body_lo - BytePos(1);
+                let comment_hi = if generics.params.len() > 0 {
+                    generics.span.lo() - BytePos(1)
+                } else {
+                    body_lo - BytePos(1)
+                };
                 let comment_lo = item.span.lo() + BytePos(lo as u32);
                 if comment_lo < comment_hi {
                     match recover_missing_comment_in_span(


Test patch:
diff --git a/tests/target/issue-5358.rs b/tests/target/issue-5358.rs
new file mode 100644
index 00000000..d4bf4909
--- /dev/null
+++ b/tests/target/issue-5358.rs
@@ -0,0 +1,4 @@
+// Test /* comment */ inside trait generics does not get duplicated.
+trait Test</* comment */ T> {}
+
+trait TestTwo</* comment */ T, /* comment */ V> {}