about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-05-29 11:29:49 +0900
committerYuki Okushi <jtitor@2k36.org>2022-05-29 11:29:49 +0900
commit5a4e9363a3fe142d5c7ea7acb8c61985fe34e704 (patch)
treed9502b7302e8f0baa06a9f8603030497015fa66c /compiler/rustc_errors/src
parent14f477e78adb9960f760e9bac812673f993d8dc2 (diff)
downloadrust-5a4e9363a3fe142d5c7ea7acb8c61985fe34e704.tar.gz
rust-5a4e9363a3fe142d5c7ea7acb8c61985fe34e704.zip
Ensure source file present when calculating max line number
Co-authored-by: Ross MacArthur <ross@macarthur.io>
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/emitter.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 5dd743e8d00..3fdc8cf8ac2 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -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);
                 }