Ensure source file present when calculating max line number

Co-authored-by: Ross MacArthur <ross@macarthur.io>
This commit is contained in:
Yuki Okushi 2022-05-29 11:29:49 +09:00
parent 14f477e78a
commit 5a4e9363a3
No known key found for this signature in database
GPG key ID: 379CEEFDD63E5DD7
3 changed files with 46 additions and 2 deletions

View file

@ -1261,16 +1261,23 @@ impl EmitterWriter {
return 0;
};
let will_be_emitted = |span: Span| {
!span.is_dummy() && {
let file = sm.lookup_source_file(span.hi());
sm.ensure_source_file_source_present(file)
}
};
let mut max = 0;
for primary_span in msp.primary_spans() {
if !primary_span.is_dummy() {
if will_be_emitted(*primary_span) {
let hi = sm.lookup_char_pos(primary_span.hi());
max = (hi.line).max(max);
}
}
if !self.short_message {
for span_label in msp.span_labels() {
if !span_label.span.is_dummy() {
if will_be_emitted(span_label.span) {
let hi = sm.lookup_char_pos(span_label.span.hi());
max = (hi.line).max(max);
}