Skip to content

Commit d162b97

Browse files
author
Jonathan Turner
committed
Teach EmitterWriter about the dangers of quasi-quoting
1 parent 1fd014a commit d162b97

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/librustc_errors/emitter.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ impl EmitterWriter {
166166

167167
if let Some(ref cm) = self.cm {
168168
for span_label in msp.span_labels() {
169+
if span_label.span == DUMMY_SP || span_label.span == COMMAND_LINE_SP {
170+
continue;
171+
}
169172
let lo = cm.lookup_char_pos(span_label.span.lo);
170173
let mut hi = cm.lookup_char_pos(span_label.span.hi);
171174
let mut is_minimized = false;
@@ -386,15 +389,19 @@ impl EmitterWriter {
386389
let mut max = 0;
387390
if let Some(ref cm) = self.cm {
388391
for primary_span in msp.primary_spans() {
389-
let hi = cm.lookup_char_pos(primary_span.hi);
390-
if hi.line > max {
391-
max = hi.line;
392+
if primary_span != &DUMMY_SP && primary_span != &COMMAND_LINE_SP {
393+
let hi = cm.lookup_char_pos(primary_span.hi);
394+
if hi.line > max {
395+
max = hi.line;
396+
}
392397
}
393398
}
394399
for span_label in msp.span_labels() {
395-
let hi = cm.lookup_char_pos(span_label.span.hi);
396-
if hi.line > max {
397-
max = hi.line;
400+
if span_label.span != DUMMY_SP && span_label.span != COMMAND_LINE_SP {
401+
let hi = cm.lookup_char_pos(span_label.span.hi);
402+
if hi.line > max {
403+
max = hi.line;
404+
}
398405
}
399406
}
400407
}
@@ -456,7 +463,13 @@ impl EmitterWriter {
456463
let primary_lo =
457464
if let (Some(ref cm), Some(ref primary_span)) = (self.cm.as_ref(),
458465
msp.primary_span().as_ref()) {
459-
cm.lookup_char_pos(primary_span.lo)
466+
if primary_span != &&DUMMY_SP && primary_span != &&COMMAND_LINE_SP {
467+
cm.lookup_char_pos(primary_span.lo)
468+
}
469+
else {
470+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
471+
return Ok(());
472+
}
460473
} else {
461474
// If we don't have span information, emit and exit
462475
emit_to_destination(&buffer.render(), level, &mut self.dst)?;

0 commit comments

Comments
 (0)