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.
This commit is contained in:
Jorge Martin Juarez 2022-07-17 21:39:25 -04:00 committed by GitHub
parent 85fdf8ecec
commit a7bf009034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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(

View File

@ -0,0 +1,4 @@
// Test /* comment */ inside trait generics does not get duplicated.
trait Test</* comment */ T> {}
trait TestTwo</* comment */ T, /* comment */ V> {}