Skip to content

Commit

Permalink
Fix make sure out primary file comes first
Browse files Browse the repository at this point in the history
  • Loading branch information
zzau13 committed May 16, 2020
1 parent f16060f commit 8fc6202
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/librustc_errors/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,25 @@ impl AnnotateSnippetEmitterWriter {
if let Some(source_map) = &self.source_map {
// Make sure our primary file comes first
let primary_lo = if let Some(ref primary_span) = msp.primary_span().as_ref() {
source_map.lookup_char_pos(primary_span.lo())
if primary_span.is_dummy() {
// FIXME(#59346): Not sure when this is the case and what
// should be done if it happens
return;
} else {
source_map.lookup_char_pos(primary_span.lo())
}
} else {
// FIXME(#59346): Not sure when this is the case and what
// should be done if it happens
return;
};
let annotated_files =
let mut annotated_files =
FileWithAnnotatedLines::collect_annotations(msp, &self.source_map);
if let Ok(pos) =
annotated_files.binary_search_by(|x| x.file.name.cmp(&primary_lo.file.name))
{
annotated_files.swap(0, pos);
}
// owned: line source, line index, annotations
type Owned = (String, usize, Vec<crate::snippet::Annotation>);
let origin = primary_lo.file.name.to_string();
Expand Down

0 comments on commit 8fc6202

Please sign in to comment.