Skip to content

Commit 8074a88

Browse files
committed
Position span label correctly when it isn't last
1 parent 5aa3403 commit 8074a88

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/librustc_errors/emitter.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,11 @@ impl EmitterWriter {
445445
&& next.has_label()) // multiline start/end, move it to a new line
446446
|| (annotation.has_label() // so as not to overlap the orizontal lines.
447447
&& next.takes_space())
448-
|| (annotation.takes_space()
449-
&& next.takes_space())
448+
|| (annotation.takes_space() && next.takes_space())
449+
|| (overlaps(next, annotation, l)
450+
&& next.end_col <= annotation.end_col
451+
&& next.has_label()
452+
&& p == 0) // Avoid #42595.
450453
{
451454
// This annotation needs a new line in the output.
452455
p += 1;

src/libsyntax/test_snippet.rs

+43
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,49 @@ error: foo
735735
"#);
736736
}
737737

738+
#[test]
739+
fn multiple_labels_secondary_without_message_3() {
740+
test_harness(r#"
741+
fn foo() {
742+
a bc d
743+
}
744+
"#,
745+
vec![
746+
SpanLabel {
747+
start: Position {
748+
string: "a",
749+
count: 1,
750+
},
751+
end: Position {
752+
string: "b",
753+
count: 1,
754+
},
755+
label: "`a` is a good letter",
756+
},
757+
SpanLabel {
758+
start: Position {
759+
string: "c",
760+
count: 1,
761+
},
762+
end: Position {
763+
string: "d",
764+
count: 1,
765+
},
766+
label: "",
767+
},
768+
],
769+
r#"
770+
error: foo
771+
--> test.rs:3:3
772+
|
773+
3 | a bc d
774+
| ^^^^----
775+
| |
776+
| `a` is a good letter
777+
778+
"#);
779+
}
780+
738781
#[test]
739782
fn multiple_labels_without_message() {
740783
test_harness(r#"

0 commit comments

Comments
 (0)