Skip to content

Commit

Permalink
Rollup merge of rust-lang#42616 - estebank:span-fix, r=nikomatsakis
Browse files Browse the repository at this point in the history
Position span label correctly when it isn't last

Fix rust-lang#42595.

Before:

```
15 |     map.entry("e").or_insert(0) += 1;
   |     ---------------------------^^^^^ot use `+=` on type `&mut {integer}`
```

After:

```
15 |     map.entry("e").or_insert(0) += 1;
   |     ---------------------------^^^^^
   |     |
   |     cannot use `+=` on type `&mut {integer}`
```
  • Loading branch information
frewsxcv authored Jun 16, 2017
2 parents a311496 + 8074a88 commit f784e5f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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
| ^^^^----
| |
| `a` is a good letter
"#);
}

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

0 comments on commit f784e5f

Please sign in to comment.