Skip to content

Commit 8fc6202

Browse files
committed
Fix make sure out primary file comes first
1 parent f16060f commit 8fc6202

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/librustc_errors/annotate_snippet_emitter_writer.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,25 @@ impl AnnotateSnippetEmitterWriter {
104104
if let Some(source_map) = &self.source_map {
105105
// Make sure our primary file comes first
106106
let primary_lo = if let Some(ref primary_span) = msp.primary_span().as_ref() {
107-
source_map.lookup_char_pos(primary_span.lo())
107+
if primary_span.is_dummy() {
108+
// FIXME(#59346): Not sure when this is the case and what
109+
// should be done if it happens
110+
return;
111+
} else {
112+
source_map.lookup_char_pos(primary_span.lo())
113+
}
108114
} else {
109115
// FIXME(#59346): Not sure when this is the case and what
110116
// should be done if it happens
111117
return;
112118
};
113-
let annotated_files =
119+
let mut annotated_files =
114120
FileWithAnnotatedLines::collect_annotations(msp, &self.source_map);
121+
if let Ok(pos) =
122+
annotated_files.binary_search_by(|x| x.file.name.cmp(&primary_lo.file.name))
123+
{
124+
annotated_files.swap(0, pos);
125+
}
115126
// owned: line source, line index, annotations
116127
type Owned = (String, usize, Vec<crate::snippet::Annotation>);
117128
let origin = primary_lo.file.name.to_string();

0 commit comments

Comments
 (0)