Require the code mapper to be thread-safe

This commit is contained in:
John Kåre Alsaker
2018-03-03 06:26:02 +01:00
parent a857e6003e
commit 8395ce9451
3 changed files with 14 additions and 13 deletions
+5 -7
View File
@@ -12,7 +12,7 @@
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan};
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId};
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapperDyn, DiagnosticId};
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
use styled_buffer::StyledBuffer;
@@ -120,7 +120,7 @@ fn to_color_choice(&self) -> ColorChoice {
pub struct EmitterWriter {
dst: Destination,
cm: Option<Lrc<CodeMapper>>,
cm: Option<Lrc<CodeMapperDyn>>,
short_message: bool,
teach: bool,
ui_testing: bool,
@@ -134,7 +134,7 @@ struct FileWithAnnotatedLines {
impl EmitterWriter {
pub fn stderr(color_config: ColorConfig,
code_map: Option<Lrc<CodeMapper>>,
code_map: Option<Lrc<CodeMapperDyn>>,
short_message: bool,
teach: bool)
-> EmitterWriter {
@@ -149,7 +149,7 @@ pub fn stderr(color_config: ColorConfig,
}
pub fn new(dst: Box<Write + Send>,
code_map: Option<Lrc<CodeMapper>>,
code_map: Option<Lrc<CodeMapperDyn>>,
short_message: bool,
teach: bool)
-> EmitterWriter {
@@ -1195,8 +1195,6 @@ fn emit_suggestion_default(&mut self,
level: &Level,
max_line_num_len: usize)
-> io::Result<()> {
use std::borrow::Borrow;
if let Some(ref cm) = self.cm {
let mut buffer = StyledBuffer::new();
@@ -1213,7 +1211,7 @@ fn emit_suggestion_default(&mut self,
Some(Style::HeaderMsg));
// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(cm.borrow());
let suggestions = suggestion.splice_lines(&**cm);
let mut row_num = 2;
for &(ref complete, ref parts) in suggestions.iter().take(MAX_SUGGESTIONS) {
+7 -4
View File
@@ -36,7 +36,7 @@
use emitter::{Emitter, EmitterWriter};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::sync::{self, Lrc};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::StableHasher;
@@ -106,6 +106,8 @@ pub struct SubstitutionPart {
pub snippet: String,
}
pub type CodeMapperDyn = CodeMapper + sync::Send + sync::Sync;
pub trait CodeMapper {
fn lookup_char_pos(&self, pos: BytePos) -> Loc;
fn span_to_lines(&self, sp: Span) -> FileLinesResult;
@@ -119,7 +121,8 @@ pub trait CodeMapper {
impl CodeSuggestion {
/// Returns the assembled code suggestions and whether they should be shown with an underline.
pub fn splice_lines(&self, cm: &CodeMapper) -> Vec<(String, Vec<SubstitutionPart>)> {
pub fn splice_lines(&self, cm: &CodeMapperDyn)
-> Vec<(String, Vec<SubstitutionPart>)> {
use syntax_pos::{CharPos, Loc, Pos};
fn push_trailing(buf: &mut String,
@@ -290,7 +293,7 @@ impl Handler {
pub fn with_tty_emitter(color_config: ColorConfig,
can_emit_warnings: bool,
treat_err_as_bug: bool,
cm: Option<Lrc<CodeMapper>>)
cm: Option<Lrc<CodeMapperDyn>>)
-> Handler {
Handler::with_tty_emitter_and_flags(
color_config,
@@ -303,7 +306,7 @@ pub fn with_tty_emitter(color_config: ColorConfig,
}
pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
cm: Option<Lrc<CodeMapper>>,
cm: Option<Lrc<CodeMapperDyn>>,
flags: HandlerFlags)
-> Handler {
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
+2 -2
View File
@@ -26,7 +26,7 @@
use errors::DiagnosticId;
use errors::emitter::{Emitter, EmitterWriter};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::sync::{self, Lrc};
use std::io::{self, Write};
use std::vec;
use std::sync::{Arc, Mutex};
@@ -36,7 +36,7 @@
pub struct JsonEmitter {
dst: Box<Write + Send>,
registry: Option<Registry>,
cm: Lrc<CodeMapper + 'static>,
cm: Lrc<CodeMapper + sync::Send + sync::Sync>,
pretty: bool,
/// Whether "approximate suggestions" are enabled in the config
approximate_suggestions: bool,