Skip to content

Commit

Permalink
Simplify a conditional in collect_annotations
Browse files Browse the repository at this point in the history
Also avoid excessive cloning
  • Loading branch information
AnthonyMikh authored Sep 30, 2019
1 parent 9d73176 commit 55b5428
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,33 +1707,28 @@ impl FileWithAnnotatedLines {
hi.col_display += 1;
}

let ann_type = if lo.line != hi.line {
if lo.line != hi.line {
let ml = MultilineAnnotation {
depth: 1,
line_start: lo.line,
line_end: hi.line,
start_col: lo.col_display,
end_col: hi.col_display,
is_primary: span_label.is_primary,
label: span_label.label.clone(),
label: span_label.label,
overlaps_exactly: false,
};
multiline_annotations.push((lo.file.clone(), ml.clone()));
AnnotationType::Multiline(ml)
multiline_annotations.push((lo.file, ml));
} else {
AnnotationType::Singleline
};
let ann = Annotation {
start_col: lo.col_display,
end_col: hi.col_display,
is_primary: span_label.is_primary,
label: span_label.label.clone(),
annotation_type: ann_type,
};

if !ann.is_multiline() {
let ann = Annotation {
start_col: lo.col_display,
end_col: hi.col_display,
is_primary: span_label.is_primary,
label: span_label.label,
annotation_type: AnnotationType::Singleline,
};
add_annotation_to_file(&mut output, lo.file, lo.line, ann);
}
};
}
}

Expand Down

0 comments on commit 55b5428

Please sign in to comment.