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;
pub struct EmitterWriter {
dst: Destination,
- cm: Option<Lrc<CodeMapper>>,
+ cm: Option<Lrc<CodeMapperDyn>>,
short_message: bool,
teach: bool,
ui_testing: bool,
impl EmitterWriter {
pub fn stderr(color_config: ColorConfig,
- code_map: Option<Lrc<CodeMapper>>,
+ code_map: Option<Lrc<CodeMapperDyn>>,
short_message: bool,
teach: bool)
-> EmitterWriter {
}
pub fn new(dst: Box<Write + Send>,
- code_map: Option<Lrc<CodeMapper>>,
+ code_map: Option<Lrc<CodeMapperDyn>>,
short_message: bool,
teach: bool)
-> 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();
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) {
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;
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;
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,
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,
}
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));
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};
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,