fix: don't duplicate type bounds when a comment precedes the where clause - #6980
Open
shulaoda wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #6234.
rewrite_where_clausetakes aspan_end_before_whereargument marking where the source it still has to account for begins.missing_span_before_after_whereturns it into the span handed torewrite_missing_comment:rewrite_typassedgenerics.span.hi()for that argument, which points just past the type alias generics. The bounds sit between there and thewherekeyword, andrewrite_tywrites them intoresultitself a few lines earlier, so the span covered text that had already been emitted. When that region also holds a comment,rewrite_missing_commentemits the whole region and the bounds come out a second time.type Bar<'a>: Baz1 // commentfollowed by a where clause formatted totype Bar<'a>: Baz1and then: Baz1 // commenton the next line, which does not parse.Recording the end of the last bound as the span start, in the same branch that writes the bounds, restores the contract. Aliases without bounds keep
generics.span.hi(), since nothing between the generics and thewherehas been written at that point.Review notes
#6815 was forked out of this issue and is not addressed here. There the comment sits between the bounds and the
;of an alias that has no where clause, a region no span is computed for at all, so it needs new handling rather than a corrected argument.