Skip to content

parse: add machine-applicable suggestion to FrontmatterExtraCharactersAfterClose#153234

Open
KernelKraze wants to merge 1 commit intorust-lang:mainfrom
KernelKraze:contribute/doc-and-diag-improvements
Open

parse: add machine-applicable suggestion to FrontmatterExtraCharactersAfterClose#153234
KernelKraze wants to merge 1 commit intorust-lang:mainfrom
KernelKraze:contribute/doc-and-diag-improvements

Conversation

@KernelKraze
Copy link

FrontmatterExtraCharactersAfterClose previously emitted an error pointing at
the 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 via rustfix and cargo 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 the
unexpected trailing text.

In addition, this PR documents three previously undocumented items in
rustc_lexer:

TokenKind::Frontmatter — describes the two flag fields and when they are
set, and links to the tracking issue.
FrontmatterAllowed — explains why the enum exists and which variant callers
should use.
Cursor::eat_until — explains the memchr-based implementation and the
"up to but not including" semantics.

Part of #136889
r? @epage

Copilot AI review requested due to automatic review settings February 28, 2026 19:47
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 28, 2026

This comment was marked as spam.

@rust-log-analyzer

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.
@KernelKraze KernelKraze force-pushed the contribute/doc-and-diag-improvements branch from 7418666 to 76fb3d7 Compare February 28, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants