Fix formatting of commented-out empty generic bounds#6838
Fix formatting of commented-out empty generic bounds#6838Marsman1996 wants to merge 1 commit intorust-lang:mainfrom
Conversation
| self.ident.span.hi() | ||
| self.colon_span | ||
| .map_or(self.ident.span.hi(), |colon_span| colon_span.hi()) |
There was a problem hiding this comment.
Can you help me understand how updating the span fixes the issue?
There was a problem hiding this comment.
Before the fix
The T: /*?Sized*/, is parsed into T and : /*?Sized*/,.
For : /*?Sized*/,, extract_post_comment removes the : but keeps the , here:
Lines 635 to 636 in bdab101
Since the remaining is start with the comment, so write_list adds an extra , here:
Line 423 in bdab101
After the fix
The T: /*?Sized*/, is parsed into T: and /*?Sized*/,.
So extract_post_comment removes the original , here:
Lines 644 to 647 in bdab101
There was a problem hiding this comment.
Thanks for the explanation. It makes sense now. My initial thought is that it seems like a simple fix, but it also feels a little weird to extend the T -> T:. I want to think a bit more on the proposed solution to this one, but I'll get back to you.
There was a problem hiding this comment.
I do not think it is too weird, because for an ordinary bound like G: SpinGuardian, the GenericParam span G: SpinGuardian already includes the :.
And I also tried to fix by adding the , removal logic in extract_post_comment, but it will remove the /*?Sized*/ comment:
impl<T: /*Sized*/, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}is formatted to
impl<T, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}There was a problem hiding this comment.
Is that comment removal expected?
When I format
impl<T: /*Size*/ SpinGuardian, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}rustfmt also removes the inline comment and produces
impl<T: SpinGuardian, G: SpinGuardian> RwLockUpgradeableGuard<'_, T, G> {}
Fix #6837
Now for code
The format result is