Skip to content

Commit 8395ce9

Browse files
committed
Require the code mapper to be thread-safe
1 parent a857e60 commit 8395ce9

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/librustc_errors/emitter.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use self::Destination::*;
1212

1313
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan};
1414

15-
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId};
15+
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapperDyn, DiagnosticId};
1616
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
1717
use styled_buffer::StyledBuffer;
1818

@@ -120,7 +120,7 @@ impl ColorConfig {
120120

121121
pub struct EmitterWriter {
122122
dst: Destination,
123-
cm: Option<Lrc<CodeMapper>>,
123+
cm: Option<Lrc<CodeMapperDyn>>,
124124
short_message: bool,
125125
teach: bool,
126126
ui_testing: bool,
@@ -134,7 +134,7 @@ struct FileWithAnnotatedLines {
134134

135135
impl EmitterWriter {
136136
pub fn stderr(color_config: ColorConfig,
137-
code_map: Option<Lrc<CodeMapper>>,
137+
code_map: Option<Lrc<CodeMapperDyn>>,
138138
short_message: bool,
139139
teach: bool)
140140
-> EmitterWriter {
@@ -149,7 +149,7 @@ impl EmitterWriter {
149149
}
150150

151151
pub fn new(dst: Box<Write + Send>,
152-
code_map: Option<Lrc<CodeMapper>>,
152+
code_map: Option<Lrc<CodeMapperDyn>>,
153153
short_message: bool,
154154
teach: bool)
155155
-> EmitterWriter {
@@ -1195,8 +1195,6 @@ impl EmitterWriter {
11951195
level: &Level,
11961196
max_line_num_len: usize)
11971197
-> io::Result<()> {
1198-
use std::borrow::Borrow;
1199-
12001198
if let Some(ref cm) = self.cm {
12011199
let mut buffer = StyledBuffer::new();
12021200

@@ -1213,7 +1211,7 @@ impl EmitterWriter {
12131211
Some(Style::HeaderMsg));
12141212

12151213
// Render the replacements for each suggestion
1216-
let suggestions = suggestion.splice_lines(cm.borrow());
1214+
let suggestions = suggestion.splice_lines(&**cm);
12171215

12181216
let mut row_num = 2;
12191217
for &(ref complete, ref parts) in suggestions.iter().take(MAX_SUGGESTIONS) {

src/librustc_errors/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use self::Level::*;
3636

3737
use emitter::{Emitter, EmitterWriter};
3838

39-
use rustc_data_structures::sync::Lrc;
39+
use rustc_data_structures::sync::{self, Lrc};
4040
use rustc_data_structures::fx::FxHashSet;
4141
use rustc_data_structures::stable_hasher::StableHasher;
4242

@@ -106,6 +106,8 @@ pub struct SubstitutionPart {
106106
pub snippet: String,
107107
}
108108

109+
pub type CodeMapperDyn = CodeMapper + sync::Send + sync::Sync;
110+
109111
pub trait CodeMapper {
110112
fn lookup_char_pos(&self, pos: BytePos) -> Loc;
111113
fn span_to_lines(&self, sp: Span) -> FileLinesResult;
@@ -119,7 +121,8 @@ pub trait CodeMapper {
119121

120122
impl CodeSuggestion {
121123
/// Returns the assembled code suggestions and whether they should be shown with an underline.
122-
pub fn splice_lines(&self, cm: &CodeMapper) -> Vec<(String, Vec<SubstitutionPart>)> {
124+
pub fn splice_lines(&self, cm: &CodeMapperDyn)
125+
-> Vec<(String, Vec<SubstitutionPart>)> {
123126
use syntax_pos::{CharPos, Loc, Pos};
124127

125128
fn push_trailing(buf: &mut String,
@@ -290,7 +293,7 @@ impl Handler {
290293
pub fn with_tty_emitter(color_config: ColorConfig,
291294
can_emit_warnings: bool,
292295
treat_err_as_bug: bool,
293-
cm: Option<Lrc<CodeMapper>>)
296+
cm: Option<Lrc<CodeMapperDyn>>)
294297
-> Handler {
295298
Handler::with_tty_emitter_and_flags(
296299
color_config,
@@ -303,7 +306,7 @@ impl Handler {
303306
}
304307

305308
pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
306-
cm: Option<Lrc<CodeMapper>>,
309+
cm: Option<Lrc<CodeMapperDyn>>,
307310
flags: HandlerFlags)
308311
-> Handler {
309312
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));

src/libsyntax/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
2626
use errors::DiagnosticId;
2727
use errors::emitter::{Emitter, EmitterWriter};
2828

29-
use rustc_data_structures::sync::Lrc;
29+
use rustc_data_structures::sync::{self, Lrc};
3030
use std::io::{self, Write};
3131
use std::vec;
3232
use std::sync::{Arc, Mutex};
@@ -36,7 +36,7 @@ use rustc_serialize::json::{as_json, as_pretty_json};
3636
pub struct JsonEmitter {
3737
dst: Box<Write + Send>,
3838
registry: Option<Registry>,
39-
cm: Lrc<CodeMapper + 'static>,
39+
cm: Lrc<CodeMapper + sync::Send + sync::Sync>,
4040
pretty: bool,
4141
/// Whether "approximate suggestions" are enabled in the config
4242
approximate_suggestions: bool,

0 commit comments

Comments
 (0)