Rollup merge of #68326 - ollie27:rustdoc_hightlight_fatal_errors, r=GuillaumeGomez
rustdoc: Catch fatal errors when syntax highlighting For some errors the lexer will unwind so we need to handle that in addition to handling `token::Unknown`. Fixes #56885 r? @GuillaumeGomez
This commit is contained in:
commit
0dc2557c12
@ -41,7 +41,7 @@ pub fn render_with_highlighting(
|
||||
let fm = sess
|
||||
.source_map()
|
||||
.new_source_file(FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned());
|
||||
let highlight_result = {
|
||||
let highlight_result = rustc_driver::catch_fatal_errors(|| {
|
||||
let lexer = lexer::StringReader::new(&sess, fm, None);
|
||||
let mut classifier = Classifier::new(lexer, sess.source_map());
|
||||
|
||||
@ -51,7 +51,8 @@ pub fn render_with_highlighting(
|
||||
} else {
|
||||
Ok(String::from_utf8_lossy(&highlighted_source).into_owned())
|
||||
}
|
||||
};
|
||||
})
|
||||
.unwrap_or(Err(()));
|
||||
|
||||
match highlight_result {
|
||||
Ok(highlighted_source) => {
|
||||
|
@ -40,7 +40,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
|
||||
dox[code_block.code].to_owned(),
|
||||
);
|
||||
|
||||
let validation_status = {
|
||||
let validation_status = rustc_driver::catch_fatal_errors(|| {
|
||||
let mut has_syntax_errors = false;
|
||||
let mut only_whitespace = true;
|
||||
// even if there is a syntax error, we need to run the lexer over the whole file
|
||||
@ -61,7 +61,8 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
})
|
||||
.unwrap_or(Some(CodeBlockInvalid::SyntaxError));
|
||||
|
||||
if let Some(code_block_invalid) = validation_status {
|
||||
let mut diag = if let Some(sp) =
|
||||
|
@ -93,3 +93,9 @@ pub fn empty_rust_with_whitespace() {}
|
||||
///
|
||||
pub fn indent_after_fenced() {}
|
||||
//~^^^ WARNING could not parse code block as Rust code
|
||||
|
||||
/// ```
|
||||
/// "invalid
|
||||
/// ```
|
||||
pub fn invalid() {}
|
||||
//~^^^^ WARNING could not parse code block as Rust code
|
||||
|
@ -132,3 +132,18 @@ LL | /// \____/
|
||||
|
|
||||
= note: error from rustc: unknown start of token: \
|
||||
|
||||
warning: could not parse code block as Rust code
|
||||
--> $DIR/invalid-syntax.rs:97:5
|
||||
|
|
||||
LL | /// ```
|
||||
| _____^
|
||||
LL | | /// "invalid
|
||||
LL | | /// ```
|
||||
| |_______^
|
||||
|
|
||||
= note: error from rustc: unterminated double quote string
|
||||
help: mark blocks that do not contain Rust code as text
|
||||
|
|
||||
LL | /// ```text
|
||||
| ^^^^^^^
|
||||
|
||||
|
@ -33,3 +33,10 @@ pub fn ok() {}
|
||||
/// <script>alert("not valid Rust");</script>
|
||||
/// ```
|
||||
pub fn escape() {}
|
||||
|
||||
// @has bad_codeblock_syntax/fn.unterminated.html
|
||||
// @has - '//*[@class="docblock"]/pre/code' '"unterminated'
|
||||
/// ```
|
||||
/// "unterminated
|
||||
/// ```
|
||||
pub fn unterminated() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user