Description
Rustdoc processes code inside of ```
blocks in two ways:
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.