use silent emitter for rustdoc highlighting pass
This commit is contained in:
parent
b43a682259
commit
d06a4ded13
@ -424,6 +424,14 @@ fn should_show_explain(&self) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
@ -17,10 +17,9 @@
|
||||
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 @@ pub fn output_file(&self) -> &Option<PathBuf> {
|
||||
|
||||
/// 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());
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
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(),
|
||||
|
@ -6,7 +6,7 @@
|
||||
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};
|
||||
@ -104,6 +104,12 @@ pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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__/
|
||||
| ^
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user