about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorOliver Middleton <olliemail27@gmail.com>2020-01-17 23:44:44 +0000
committerOliver Middleton <olliemail27@gmail.com>2020-01-17 23:44:44 +0000
commit79061d0e02f70ecbf3333057eac36dcc6c4b1727 (patch)
tree0f1265828c4af8564a78159a2ff2acee54a655c0 /src/librustdoc/html
parent689fca01c5a1eac2d240bf08aa728171a28f2285 (diff)
downloadrust-79061d0e02f70ecbf3333057eac36dcc6c4b1727.tar.gz
rust-79061d0e02f70ecbf3333057eac36dcc6c4b1727.zip
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`.
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/highlight.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index aa52b769c38..5bea1b56141 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -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) => {