diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-06-16 00:32:42 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-16 00:32:42 -0400 |
| commit | f784e5f13624f07df27ab76bfd8c8b40f92731bb (patch) | |
| tree | 0fb6e02bdae2171b38639f29ad3c44336feba9a9 /src | |
| parent | a3114961a1c6b8a16cd06a854d585377ac576d47 (diff) | |
| parent | 8074a88787de412a341e99ea16c88784ecf915a0 (diff) | |
| download | rust-f784e5f13624f07df27ab76bfd8c8b40f92731bb.tar.gz rust-f784e5f13624f07df27ab76bfd8c8b40f92731bb.zip | |
Rollup merge of #42616 - estebank:span-fix, r=nikomatsakis
Position span label correctly when it isn't last
Fix #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}`
```
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/test_snippet.rs | 43 |
2 files changed, 48 insertions, 2 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index f820ea4c5e1..aa0fae508fd 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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; diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index b3fa1e97376..4fae2ff9814 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -736,6 +736,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#" fn foo() { |
