about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-11-06 03:28:11 +0100
committerGitHub <noreply@github.com>2019-11-06 03:28:11 +0100
commitf5c54896b9ff6bd62ffd3c8b9d2b2c4e7461d380 (patch)
tree54e565376f1c1353187e785851d01369c059e386 /src
parente5da1a12e745e0d92cfae421673faac4fd5e4069 (diff)
parentd06a4ded13b948a6a5b546514ccc7009097f145a (diff)
downloadrust-f5c54896b9ff6bd62ffd3c8b9d2b2c4e7461d380.tar.gz
rust-f5c54896b9ff6bd62ffd3c8b9d2b2c4e7461d380.zip
Rollup merge of #66068 - euclio:null-emitter, r=estebank
use silent emitter for rustdoc highlighting pass

Partially addresses #63284.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_errors/emitter.rs8
-rw-r--r--src/librustc_interface/interface.rs14
-rw-r--r--src/librustdoc/html/highlight.rs4
-rw-r--r--src/libsyntax/sess.rs8
-rw-r--r--src/test/rustdoc-ui/invalid-syntax.stderr64
5 files changed, 19 insertions, 79 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index b153f0f0e82..5f74df13fae 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -424,6 +424,14 @@ impl Emitter for EmitterWriter {
     }
 }
 
+/// An emitter that does nothing when emitting a diagnostic.
+pub struct SilentEmitter;
+
+impl Emitter for SilentEmitter {
+    fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
+    fn emit_diagnostic(&mut self, _: &Diagnostic) {}
+}
+
 /// maximum number of lines we will print for each error; arbitrary.
 pub const MAX_HIGHLIGHT_LINES: usize = 6;
 /// maximum number of suggestions to be shown
diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs
index e014e4ed0fd..4e4d6d982fb 100644
--- a/src/librustc_interface/interface.rs
+++ b/src/librustc_interface/interface.rs
@@ -17,10 +17,9 @@ use std::sync::{Arc, Mutex};
 use syntax::{self, parse};
 use syntax::ast::{self, MetaItemKind};
 use syntax::parse::token;
-use syntax::source_map::{FileName, FilePathMapping, FileLoader, SourceMap};
+use syntax::source_map::{FileName, FileLoader, SourceMap};
 use syntax::sess::ParseSess;
 use syntax_pos::edition;
-use rustc_errors::{Diagnostic, emitter::Emitter, Handler, SourceMapperDyn};
 
 pub type Result<T> = result::Result<T, ErrorReported>;
 
@@ -63,18 +62,9 @@ impl Compiler {
 
 /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
 pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
-    struct NullEmitter;
-    impl Emitter for NullEmitter {
-        fn emit_diagnostic(&mut self, _: &Diagnostic) {}
-        fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
-    }
-
     syntax::with_default_globals(move || {
         let cfg = cfgspecs.into_iter().map(|s| {
-
-            let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
-            let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
-            let sess = ParseSess::with_span_handler(handler, cm);
+            let sess = ParseSess::with_silent_emitter();
             let filename = FileName::cfg_spec_source_code(&s);
             let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
 
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index 30c9453a643..88ba13f2796 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -11,7 +11,7 @@ use std::fmt::Display;
 use std::io;
 use std::io::prelude::*;
 
-use syntax::source_map::{SourceMap, FilePathMapping};
+use syntax::source_map::SourceMap;
 use syntax::parse::lexer;
 use syntax::parse::token::{self, Token};
 use syntax::sess::ParseSess;
@@ -33,7 +33,7 @@ pub fn render_with_highlighting(
                class, tooltip).unwrap();
     }
 
-    let sess = ParseSess::new(FilePathMapping::empty());
+    let sess = ParseSess::with_silent_emitter();
     let fm = sess.source_map().new_source_file(
         FileName::Custom(String::from("rustdoc-highlighting")),
         src.to_owned(),
diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs
index 323fe01f067..30f8c56a056 100644
--- a/src/libsyntax/sess.rs
+++ b/src/libsyntax/sess.rs
@@ -6,7 +6,7 @@ use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId};
 use crate::source_map::{SourceMap, FilePathMapping};
 use crate::feature_gate::UnstableFeatures;
 
-use errors::{Applicability, Handler, ColorConfig, DiagnosticBuilder};
+use errors::{Applicability, emitter::SilentEmitter, Handler, ColorConfig, DiagnosticBuilder};
 use rustc_data_structures::fx::{FxHashSet, FxHashMap};
 use rustc_data_structures::sync::{Lrc, Lock, Once};
 use syntax_pos::{Symbol, Span, MultiSpan};
@@ -107,6 +107,12 @@ impl ParseSess {
         }
     }
 
+    pub fn with_silent_emitter() -> Self {
+        let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
+        let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter));
+        ParseSess::with_span_handler(handler, cm)
+    }
+
     #[inline]
     pub fn source_map(&self) -> &SourceMap {
         &self.source_map
diff --git a/src/test/rustdoc-ui/invalid-syntax.stderr b/src/test/rustdoc-ui/invalid-syntax.stderr
index 8ec4338e13f..84c10028fd1 100644
--- a/src/test/rustdoc-ui/invalid-syntax.stderr
+++ b/src/test/rustdoc-ui/invalid-syntax.stderr
@@ -222,67 +222,3 @@ warning: could not parse code block as Rust code
 LL | ///     \____/
    |         ^^^^^^
 
-error: unknown start of token: \
- --> <rustdoc-highlighting>:1:1
-  |
-1 | \____/
-  | ^
-
-error: unknown start of token: \
- --> <rustdoc-highlighting>:1:1
-  |
-1 | \_
-  | ^
-
-error: unknown start of token: \
- --> <rustdoc-highlighting>:1:1
-  |
-1 | \_
-  | ^
-
-error: unknown start of token: `
- --> <rustdoc-highlighting>:1:1
-  |
-1 | ```
-  | ^
-  |
-help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
-  |
-1 | '``
-  | ^
-
-error: unknown start of token: \
- --> <rustdoc-highlighting>:2:1
-  |
-2 | \_
-  | ^
-
-error: unknown start of token: \
- --> <rustdoc-highlighting>:1:1
-  |
-1 | \_
-  | ^
-
-error: unknown start of token: \
- --> <rustdoc-highlighting>:1:1
-  |
-1 | \_
-  | ^
-
-error: unknown start of token: `
- --> <rustdoc-highlighting>:3:30
-  |
-3 |    |     ^^^^^^ did you mean `baz::foobar`?
-  |                              ^
-  |
-help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
-  |
-3 |    |     ^^^^^^ did you mean 'baz::foobar`?
-  |                              ^
-
-error: unknown start of token: \
- --> <rustdoc-highlighting>:1:1
-  |
-1 | \__________pkt->size___________/          \_result->size_/ \__pkt->size__/
-  | ^
-