@@ -434,34 +434,31 @@ pub trait Emitter {
434
434
span: &mut MultiSpan,
435
435
children: &mut Vec<SubDiagnostic>,
436
436
) {
437
+ let source_map = if let Some(ref sm) = source_map {
438
+ sm
439
+ } else {
440
+ return;
441
+ };
437
442
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
438
- for span in iter::once(&mut *span).chain(children.iter_mut().map(|child| &mut child.span)) {
439
- self.fix_multispan_in_extern_macros(source_map, span);
443
+ self.fix_multispan_in_extern_macros(source_map, span);
444
+ for child in children.iter_mut() {
445
+ self.fix_multispan_in_extern_macros(source_map, &mut child.span);
440
446
}
441
447
debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
442
448
}
443
449
444
450
// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
445
451
// Since these locations are often difficult to read,
446
452
// we move these spans from the external macros to their corresponding use site.
447
- fn fix_multispan_in_extern_macros(
448
- &self,
449
- source_map: &Option<Lrc<SourceMap>>,
450
- span: &mut MultiSpan,
451
- ) {
452
- let sm = match source_map {
453
- Some(ref sm) => sm,
454
- None => return,
455
- };
456
-
453
+ fn fix_multispan_in_extern_macros(&self, source_map: &Lrc<SourceMap>, span: &mut MultiSpan) {
457
454
// First, find all the spans in external macros and point instead at their use site.
458
455
let replacements: Vec<(Span, Span)> = span
459
456
.primary_spans()
460
457
.iter()
461
458
.copied()
462
459
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
463
460
.filter_map(|sp| {
464
- if !sp.is_dummy() && sm .is_imported(sp) {
461
+ if !sp.is_dummy() && source_map .is_imported(sp) {
465
462
let maybe_callsite = sp.source_callsite();
466
463
if sp != maybe_callsite {
467
464
return Some((sp, maybe_callsite));
@@ -1232,7 +1229,6 @@ impl EmitterWriter {
1232
1229
is_secondary: bool,
1233
1230
) -> io::Result<()> {
1234
1231
let mut buffer = StyledBuffer::new();
1235
- let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
1236
1232
1237
1233
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
1238
1234
{
@@ -1257,6 +1253,7 @@ impl EmitterWriter {
1257
1253
buffer.append(0, &code, Style::Level(*level));
1258
1254
buffer.append(0, "]", Style::Level(*level));
1259
1255
}
1256
+ let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
1260
1257
if *level != Level::FailureNote {
1261
1258
buffer.append(0, ": ", header_style);
1262
1259
}
@@ -1470,9 +1467,7 @@ impl EmitterWriter {
1470
1467
let mut to_add = FxHashMap::default();
1471
1468
1472
1469
for (depth, style) in depths {
1473
- if multilines.get(&depth).is_some() {
1474
- multilines.remove(&depth);
1475
- } else {
1470
+ if multilines.remove(&depth).is_none() {
1476
1471
to_add.insert(depth, style);
1477
1472
}
1478
1473
}
@@ -1726,14 +1721,13 @@ impl EmitterWriter {
1726
1721
if !self.short_message {
1727
1722
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
1728
1723
}
1729
- match emit_to_destination(
1724
+ if let Err(e) = emit_to_destination(
1730
1725
&buffer.render(),
1731
1726
level,
1732
1727
&mut self.dst,
1733
1728
self.short_message,
1734
1729
) {
1735
- Ok(()) => (),
1736
- Err(e) => panic!("failed to emit error: {}", e),
1730
+ panic!("failed to emit error: {}", e)
1737
1731
}
1738
1732
}
1739
1733
if !self.short_message {
0 commit comments