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:
parent
85fdf8ecec
commit
a7bf009034
@ -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(
|
||||
|
4
tests/target/issue-5358.rs
Normal file
4
tests/target/issue-5358.rs
Normal file
@ -0,0 +1,4 @@
|
||||
// Test /* comment */ inside trait generics does not get duplicated.
|
||||
trait Test</* comment */ T> {}
|
||||
|
||||
trait TestTwo</* comment */ T, /* comment */ V> {}
|
Loading…
x
Reference in New Issue
Block a user