Rollup merge of #83427 - llogiq:refactor-emitter, r=estebank
small cleanups in rustc_errors / emitter This is either moving code around so it gets called less often or using if let instead of match in a few cases.
This commit is contained in:
commit
5ca3f0d51f
@ -434,9 +434,15 @@ pub trait Emitter {
|
|||||||
span: &mut MultiSpan,
|
span: &mut MultiSpan,
|
||||||
children: &mut Vec<SubDiagnostic>,
|
children: &mut Vec<SubDiagnostic>,
|
||||||
) {
|
) {
|
||||||
|
let source_map = if let Some(ref sm) = source_map {
|
||||||
|
sm
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
|
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
|
||||||
for span in iter::once(&mut *span).chain(children.iter_mut().map(|child| &mut child.span)) {
|
self.fix_multispan_in_extern_macros(source_map, span);
|
||||||
self.fix_multispan_in_extern_macros(source_map, span);
|
for child in children.iter_mut() {
|
||||||
|
self.fix_multispan_in_extern_macros(source_map, &mut child.span);
|
||||||
}
|
}
|
||||||
debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
|
debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
|
||||||
}
|
}
|
||||||
@ -444,16 +450,7 @@ pub trait Emitter {
|
|||||||
// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
|
// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
|
||||||
// Since these locations are often difficult to read,
|
// Since these locations are often difficult to read,
|
||||||
// we move these spans from the external macros to their corresponding use site.
|
// we move these spans from the external macros to their corresponding use site.
|
||||||
fn fix_multispan_in_extern_macros(
|
fn fix_multispan_in_extern_macros(&self, source_map: &Lrc<SourceMap>, span: &mut MultiSpan) {
|
||||||
&self,
|
|
||||||
source_map: &Option<Lrc<SourceMap>>,
|
|
||||||
span: &mut MultiSpan,
|
|
||||||
) {
|
|
||||||
let sm = match source_map {
|
|
||||||
Some(ref sm) => sm,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
// First, find all the spans in external macros and point instead at their use site.
|
// First, find all the spans in external macros and point instead at their use site.
|
||||||
let replacements: Vec<(Span, Span)> = span
|
let replacements: Vec<(Span, Span)> = span
|
||||||
.primary_spans()
|
.primary_spans()
|
||||||
@ -461,7 +458,7 @@ pub trait Emitter {
|
|||||||
.copied()
|
.copied()
|
||||||
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
|
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
|
||||||
.filter_map(|sp| {
|
.filter_map(|sp| {
|
||||||
if !sp.is_dummy() && sm.is_imported(sp) {
|
if !sp.is_dummy() && source_map.is_imported(sp) {
|
||||||
let maybe_callsite = sp.source_callsite();
|
let maybe_callsite = sp.source_callsite();
|
||||||
if sp != maybe_callsite {
|
if sp != maybe_callsite {
|
||||||
return Some((sp, maybe_callsite));
|
return Some((sp, maybe_callsite));
|
||||||
@ -1232,7 +1229,6 @@ impl EmitterWriter {
|
|||||||
is_secondary: bool,
|
is_secondary: bool,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut buffer = StyledBuffer::new();
|
let mut buffer = StyledBuffer::new();
|
||||||
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
|
|
||||||
|
|
||||||
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
|
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
|
||||||
{
|
{
|
||||||
@ -1257,6 +1253,7 @@ impl EmitterWriter {
|
|||||||
buffer.append(0, &code, Style::Level(*level));
|
buffer.append(0, &code, Style::Level(*level));
|
||||||
buffer.append(0, "]", Style::Level(*level));
|
buffer.append(0, "]", Style::Level(*level));
|
||||||
}
|
}
|
||||||
|
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
|
||||||
if *level != Level::FailureNote {
|
if *level != Level::FailureNote {
|
||||||
buffer.append(0, ": ", header_style);
|
buffer.append(0, ": ", header_style);
|
||||||
}
|
}
|
||||||
@ -1470,9 +1467,7 @@ impl EmitterWriter {
|
|||||||
let mut to_add = FxHashMap::default();
|
let mut to_add = FxHashMap::default();
|
||||||
|
|
||||||
for (depth, style) in depths {
|
for (depth, style) in depths {
|
||||||
if multilines.get(&depth).is_some() {
|
if multilines.remove(&depth).is_none() {
|
||||||
multilines.remove(&depth);
|
|
||||||
} else {
|
|
||||||
to_add.insert(depth, style);
|
to_add.insert(depth, style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1726,14 +1721,13 @@ impl EmitterWriter {
|
|||||||
if !self.short_message {
|
if !self.short_message {
|
||||||
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
|
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
|
||||||
}
|
}
|
||||||
match emit_to_destination(
|
if let Err(e) = emit_to_destination(
|
||||||
&buffer.render(),
|
&buffer.render(),
|
||||||
level,
|
level,
|
||||||
&mut self.dst,
|
&mut self.dst,
|
||||||
self.short_message,
|
self.short_message,
|
||||||
) {
|
) {
|
||||||
Ok(()) => (),
|
panic!("failed to emit error: {}", e)
|
||||||
Err(e) => panic!("failed to emit error: {}", e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.short_message {
|
if !self.short_message {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user