Require the code mapper to be thread-safe
This commit is contained in:
parent
a857e6003e
commit
8395ce9451
3 changed files with 14 additions and 13 deletions
|
|
@ -12,7 +12,7 @@ use self::Destination::*;
|
|||
|
||||
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 @@ impl ColorConfig {
|
|||
|
||||
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 @@ impl EmitterWriter {
|
|||
}
|
||||
|
||||
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 @@ impl EmitterWriter {
|
|||
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 @@ impl EmitterWriter {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ use self::Level::*;
|
|||
|
||||
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 @@ impl Handler {
|
|||
}
|
||||
|
||||
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));
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
|
|||
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 @@ use rustc_serialize::json::{as_json, as_pretty_json};
|
|||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue