Skip to content

update rustdoc's syntax checker to work with error-recovering lexer #63284

Closed
@matklad

Description

@matklad

Rustdoc processes code inside of ``` blocks in two ways:

  • First, the code is checked for lexer errors

  • Second, lexer-based syntax highlighting is done

The checking for lexer errors works by intercepting fatal errors from the lexer. However, since this was originally implemented, the lexer moved from fatal erroring to error-recovery (#63017 in particular tries to remove the last bit of fatal erroring). That means that the current approach intercepts only a fraction of lexer errors, while most of the errors are reported twice (once duing the check, once during highlighing). Here's an example:

14:30:41|~/tmp
λ cat main.rs 
/// ```
/// '...'
/// ```
pub fn foo() {}

14:31:11|~/tmp
λ rustdoc main.rs
error: character literal may only contain one codepoint
 --> <doctest>:1:1
  |
1 | '...'
  | ^^^^^
help: if you meant to write a `str` literal, use double quotes
  |
1 | "..."
  |

error: character literal may only contain one codepoint
 --> <rustdoc-highlighting>:1:1
  |
1 | '...'
  | ^^^^^
help: if you meant to write a `str` literal, use double quotes
  |
1 | "..."

I think that, to fix this, we should configure the parsing session with a custom Emitter. For code-checking pass, the emmitter should downgrade all diagnostics to warnings and set a flag if there were any diagnostics. For syntax-highlighting pass, we should use a "/dev/null" emitter which just doesn't emit anything.

cc @euclio, @GuillaumeGomez

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions