fix: don't leave trailing whitespace before a skipped impl item - #6979
Open
shulaoda wants to merge 1 commit into
Open
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 #5521.
process_missing_coderecords where a trailing whitespace run starts inSnippetStatus::last_wspace, then drops everything from that point when it reaches the newline. The check for whether to record a new start sat in theelse ifcondition:The second whitespace character of a run fails that condition and falls into the
elsebranch, which clears the start just recorded. Each whitespace character flips the state, so an even length run ends with no start recorded and survives whole, and an odd length run keeps all but its last character. Only a run of one character was trimmed correctly, which is why the bug looks intermittent.Inside an impl block this leaves whitespace on the otherwise blank line before a
#[rustfmt::skip]item. rustfmt then reportserror[internal]: left behind trailing whitespaceand stops formatting the file.Moving the
is_nonecheck inside the branch pinslast_wspaceto the first whitespace character of the run. Only a non-whitespace character clears it, so the whole run is dropped.Review notes
Whitespace characters on the blank line before the skipped item:
The skipped item has to be a non-first item of an impl block. The same whitespace in a
mod, in a function body, at the top level, or before the first impl item is trimmed elsewhere and was never affected, so the test uses that one shape for all four cases.#4706 was raised on the issue as a possible duplicate. There the whitespace is inside the body of the skipped item, which the attribute asks rustfmt to leave alone. Here it sits between the previous item and the attribute, outside any skipped span.