Simplify span fallback
This commit is contained in:
parent
b9bf119c4f
commit
9eb9176b08
@ -24,7 +24,7 @@ use rustc_lint_defs::pluralize;
|
|||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_error_messages::FluentArgs;
|
use rustc_error_messages::{FluentArgs, SpanLabel};
|
||||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp::{max, min, Reverse};
|
use std::cmp::{max, min, Reverse};
|
||||||
@ -2202,46 +2202,28 @@ impl FileWithAnnotatedLines {
|
|||||||
let mut multiline_annotations = vec![];
|
let mut multiline_annotations = vec![];
|
||||||
|
|
||||||
if let Some(ref sm) = emitter.source_map() {
|
if let Some(ref sm) = emitter.source_map() {
|
||||||
for span_label in msp.span_labels() {
|
for SpanLabel { span, is_primary, label } in msp.span_labels() {
|
||||||
let fixup_lo_hi = |span: Span| {
|
// If we don't have a useful span, pick the primary span if that exists.
|
||||||
let lo = sm.lookup_char_pos(span.lo());
|
// Worst case we'll just print an error at the top of the main file.
|
||||||
let mut hi = sm.lookup_char_pos(span.hi());
|
let span = match (span.is_dummy(), msp.primary_span()) {
|
||||||
|
(_, None) | (false, _) => span,
|
||||||
// Watch out for "empty spans". If we get a span like 6..6, we
|
(true, Some(span)) => span,
|
||||||
// want to just display a `^` at 6, so convert that to
|
|
||||||
// 6..7. This is degenerate input, but it's best to degrade
|
|
||||||
// gracefully -- and the parser likes to supply a span like
|
|
||||||
// that for EOF, in particular.
|
|
||||||
|
|
||||||
if lo.col_display == hi.col_display && lo.line == hi.line {
|
|
||||||
hi.col_display += 1;
|
|
||||||
}
|
|
||||||
(lo, hi)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if span_label.span.is_dummy() {
|
let lo = sm.lookup_char_pos(span.lo());
|
||||||
if let Some(span) = msp.primary_span() {
|
let mut hi = sm.lookup_char_pos(span.hi());
|
||||||
// if we don't know where to render the annotation, emit it as a note
|
|
||||||
// on the primary span.
|
|
||||||
|
|
||||||
let (lo, hi) = fixup_lo_hi(span);
|
// Watch out for "empty spans". If we get a span like 6..6, we
|
||||||
|
// want to just display a `^` at 6, so convert that to
|
||||||
|
// 6..7. This is degenerate input, but it's best to degrade
|
||||||
|
// gracefully -- and the parser likes to supply a span like
|
||||||
|
// that for EOF, in particular.
|
||||||
|
|
||||||
let ann = Annotation {
|
if lo.col_display == hi.col_display && lo.line == hi.line {
|
||||||
start_col: lo.col_display,
|
hi.col_display += 1;
|
||||||
end_col: hi.col_display,
|
|
||||||
is_primary: span_label.is_primary,
|
|
||||||
label: span_label
|
|
||||||
.label
|
|
||||||
.as_ref()
|
|
||||||
.map(|m| emitter.translate_message(m, args).to_string()),
|
|
||||||
annotation_type: AnnotationType::Singleline,
|
|
||||||
};
|
|
||||||
add_annotation_to_file(&mut output, lo.file, lo.line, ann);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (lo, hi) = fixup_lo_hi(span_label.span);
|
let label = label.as_ref().map(|m| emitter.translate_message(m, args).to_string());
|
||||||
|
|
||||||
if lo.line != hi.line {
|
if lo.line != hi.line {
|
||||||
let ml = MultilineAnnotation {
|
let ml = MultilineAnnotation {
|
||||||
@ -2250,11 +2232,8 @@ impl FileWithAnnotatedLines {
|
|||||||
line_end: hi.line,
|
line_end: hi.line,
|
||||||
start_col: lo.col_display,
|
start_col: lo.col_display,
|
||||||
end_col: hi.col_display,
|
end_col: hi.col_display,
|
||||||
is_primary: span_label.is_primary,
|
is_primary,
|
||||||
label: span_label
|
label,
|
||||||
.label
|
|
||||||
.as_ref()
|
|
||||||
.map(|m| emitter.translate_message(m, args).to_string()),
|
|
||||||
overlaps_exactly: false,
|
overlaps_exactly: false,
|
||||||
};
|
};
|
||||||
multiline_annotations.push((lo.file, ml));
|
multiline_annotations.push((lo.file, ml));
|
||||||
@ -2262,11 +2241,8 @@ impl FileWithAnnotatedLines {
|
|||||||
let ann = Annotation {
|
let ann = Annotation {
|
||||||
start_col: lo.col_display,
|
start_col: lo.col_display,
|
||||||
end_col: hi.col_display,
|
end_col: hi.col_display,
|
||||||
is_primary: span_label.is_primary,
|
is_primary,
|
||||||
label: span_label
|
label,
|
||||||
.label
|
|
||||||
.as_ref()
|
|
||||||
.map(|m| emitter.translate_message(m, args).to_string()),
|
|
||||||
annotation_type: AnnotationType::Singleline,
|
annotation_type: AnnotationType::Singleline,
|
||||||
};
|
};
|
||||||
add_annotation_to_file(&mut output, lo.file, lo.line, ann);
|
add_annotation_to_file(&mut output, lo.file, lo.line, ann);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user