Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position span label correctly when it isn't last #42616

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ impl EmitterWriter {
&& next.has_label()) // multiline start/end, move it to a new line
|| (annotation.has_label() // so as not to overlap the orizontal lines.
&& next.takes_space())
|| (annotation.takes_space()
&& next.takes_space())
|| (annotation.takes_space() && next.takes_space())
|| (overlaps(next, annotation, l)
&& next.end_col <= annotation.end_col
&& next.has_label()
&& p == 0) // Avoid #42595.
{
// This annotation needs a new line in the output.
p += 1;
Expand Down
43 changes: 43 additions & 0 deletions src/libsyntax/test_snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,49 @@ error: foo
"#);
}

#[test]
fn multiple_labels_secondary_without_message_3() {
test_harness(r#"
fn foo() {
a bc d
}
"#,
vec![
SpanLabel {
start: Position {
string: "a",
count: 1,
},
end: Position {
string: "b",
count: 1,
},
label: "`a` is a good letter",
},
SpanLabel {
start: Position {
string: "c",
count: 1,
},
end: Position {
string: "d",
count: 1,
},
label: "",
},
],
r#"
error: foo
--> test.rs:3:3
|
3 | a bc d
| ^^^^----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's progress for sure. I still find these sorts of overlap scenarios pretty mind boggling regardless, though i'm not sure how best to fix in general. I'd sort of like to separate the ^^^ and --- on different lines. i.e., if I was highlighting this by hand I would probably do:

a  bc  d
^^^^
    ----

but anyway.

| |
| `a` is a good letter

"#);
}

#[test]
fn multiple_labels_without_message() {
test_harness(r#"
Expand Down