parse: add machine-applicable suggestion to FrontmatterExtraCharactersAfterClose#153234
Open
KernelKraze wants to merge 1 commit intorust-lang:mainfrom
Open
parse: add machine-applicable suggestion to FrontmatterExtraCharactersAfterClose#153234KernelKraze wants to merge 1 commit intorust-lang:mainfrom
FrontmatterExtraCharactersAfterClose#153234KernelKraze wants to merge 1 commit intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
…Close` When the lexer encounters extra characters after the closing `---` fence of a frontmatter block (e.g. `---cargo`), it now emits a machine-applicable suggestion to remove them. The suggestion span is computed carefully to account for any leading whitespace before the closing dashes, so it points precisely at the unwanted characters rather than the dashes themselves. Also add doc comments to `TokenKind::Frontmatter`, `FrontmatterAllowed`, and `Cursor::eat_until` in `rustc_lexer`, which previously had none.
7418666 to
76fb3d7
Compare
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.
FrontmatterExtraCharactersAfterClosepreviously emitted an error pointing atthe entire closing fence line, but offered no automated fix. This PR adds a
machine-applicable suggestion that removes the extra characters after the
closing
---, making it actionable viarustfixandcargo fix.The suggestion span is computed from the end of the closing dashes to the end
of the line. The calculation accounts for any leading whitespace on the closing
line (e.g.
---cargo), so the suggestion correctly targets only theunexpected trailing text.
In addition, this PR documents three previously undocumented items in
rustc_lexer:TokenKind::Frontmatter— describes the two flag fields and when they areset, and links to the tracking issue.
FrontmatterAllowed— explains why the enum exists and which variant callersshould use.
Cursor::eat_until— explains thememchr-based implementation and the"up to but not including" semantics.
Part of #136889
r? @epage