Skip to content

Commit a7bf009

Browse files
authored
Fix/comments inside trait generics gets duplicated (#5446)
* Bugfix: Now slash/start comments aren't duplicated on trait parameters. * Removing unnecesary comment. * Improvements: Improving the BytePos offset. * Improvements: Improving the description of the test cases.
1 parent 85fdf8e commit a7bf009

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: src/items.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,11 @@ pub(crate) fn format_trait(
10841084
let item_snippet = context.snippet(item.span);
10851085
if let Some(lo) = item_snippet.find('/') {
10861086
// 1 = `{`
1087-
let comment_hi = body_lo - BytePos(1);
1087+
let comment_hi = if generics.params.len() > 0 {
1088+
generics.span.lo() - BytePos(1)
1089+
} else {
1090+
body_lo - BytePos(1)
1091+
};
10881092
let comment_lo = item.span.lo() + BytePos(lo as u32);
10891093
if comment_lo < comment_hi {
10901094
match recover_missing_comment_in_span(

Diff for: tests/target/issue-5358.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Test /* comment */ inside trait generics does not get duplicated.
2+
trait Test</* comment */ T> {}
3+
4+
trait TestTwo</* comment */ T, /* comment */ V> {}

0 commit comments

Comments
 (0)