Skip to content

Commit

Permalink
reorder span labels
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikholkar committed Jul 17, 2017
1 parent 5803f99 commit 26a8357
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 22 deletions.
15 changes: 13 additions & 2 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,20 @@ impl EmitterWriter {
// and "annotations lines", where the highlight lines have the `^`.

// Sort the annotations by (start, end col)
// The labels are reversed, sort and then reversed again.
// Consider a list of annotations (A1, A2, C1, C2, B1, B2) where
// the letter signifies the span. Here we are only sorting by the
// span and hence, the order of the elements with the same span will
// not change. On reversing the ordering (|a, b| but b.cmp(a)), you get
// (C1, C2, B1, B2, A1, A2). All the elements with the same span are
// still ordered first to last, but all the elements with different
// spans are ordered by their spans in last to first order. Last to
// first order is important, because the jiggly lines and | are on
// the left, so the rightmost span needs to be rendered first,
// otherwise the lines would end up needing to go over a message.

let mut annotations = line.annotations.clone();
annotations.sort();
annotations.reverse();
annotations.sort_by(|a,b| b.start_col.cmp(&a.start_col));

// First, figure out where each label will be positioned.
//
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-31424.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable argument `self` as mutable
17 | (&mut self).bar();
| ^^^^
| |
| try removing `&mut` here
| cannot reborrow mutably
| try removing `&mut` here

error[E0596]: cannot borrow immutable argument `self` as mutable
--> $DIR/issue-31424.rs:23:15
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-34126.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable argument `self` as mutable
16 | self.run(&mut self);
| ^^^^
| |
| try removing `&mut` here
| cannot reborrow mutably
| try removing `&mut` here

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-34337.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable local variable `key` as mutable
16 | get(&mut key);
| ^^^
| |
| try removing `&mut` here
| cannot reborrow mutably
| try removing `&mut` here

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-37139.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable local variable `x` as mutable
22 | test(&mut x);
| ^
| |
| try removing `&mut` here
| cannot reborrow mutably
| try removing `&mut` here

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0507]: cannot move out of indexed content
19 | let e = f.v[0];
| ^^^^^^
| |
| help: consider using a reference instead: `&f.v[0]`
| cannot move out of indexed content
| help: consider using a reference instead: `&f.v[0]`

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/mismatched_types/E0281.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0281]: type mismatch: `[closure@$DIR/E0281.rs:14:9: 14:24]` implements th
14 | foo(|y: String| { });
| ^^^ --------------- implements `std::ops::Fn<(std::string::String,)>`
| |
| requires `std::ops::Fn<(usize,)>`
| expected usize, found struct `std::string::String`
| requires `std::ops::Fn<(usize,)>`
|
= note: required by `foo`

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mismatched_types/closure-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ error[E0281]: type mismatch: `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]` im
18 | baz(|_| ());
| ^^^ ------ implements `std::ops::Fn<(_,)>`
| |
| requires `for<'r> std::ops::Fn<(&'r (),)>`
| expected concrete lifetime, found bound lifetime parameter
| requires `for<'r> std::ops::Fn<(&'r (),)>`
|
= note: required because of the requirements on the impl of `Foo` for `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]`
= note: required by `baz`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mismatched_types/issue-36053-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ error[E0281]: type mismatch: `[closure@$DIR/issue-36053-2.rs:17:39: 17:53]` impl
17 | once::<&str>("str").fuse().filter(|a: &str| true).count();
| ^^^^^^ -------------- implements `for<'r> std::ops::FnMut<(&'r str,)>`
| |
| requires `for<'r> std::ops::FnMut<(&'r &str,)>`
| expected &str, found str
| requires `for<'r> std::ops::FnMut<(&'r &str,)>`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ error[E0281]: type mismatch: `[closure@$DIR/unboxed-closures-vtable-mismatch.rs:
25 | let z = call_it(3, f);
| ^^^^^^^
| |
| requires `std::ops::FnMut<(isize, isize)>`
| expected isize, found usize
| requires `std::ops::FnMut<(isize, isize)>`
|
= note: required by `call_it`

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/resolve/issue-2356.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ error[E0425]: cannot find value `whiskers` in this scope
52 | whiskers -= other;
| ^^^^^^^^
| |
| help: try: `self.whiskers`
| `self` value is only available in methods with `self` parameter
| help: try: `self.whiskers`

error[E0425]: cannot find function `shave` in this scope
--> $DIR/issue-2356.rs:57:5
Expand Down Expand Up @@ -91,8 +91,8 @@ error[E0425]: cannot find value `whiskers` in this scope
110 | whiskers = 4;
| ^^^^^^^^
| |
| help: try: `self.whiskers`
| `self` value is only available in methods with `self` parameter
| help: try: `self.whiskers`

error[E0425]: cannot find function `purr_louder` in this scope
--> $DIR/issue-2356.rs:115:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-5035.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ error[E0404]: expected trait, found type alias `K`
13 | impl K for isize {} //~ ERROR expected trait, found type alias `K`
| ^
| |
| type aliases cannot be used for traits
| did you mean `I`?
| type aliases cannot be used for traits

error: cannot continue compilation due to previous error

6 changes: 3 additions & 3 deletions src/test/ui/resolve/privacy-struct-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ error[E0423]: expected value, found struct `Z`
26 | Z;
| ^
| |
| did you mean `Z { /* fields */ }`?
| did you mean `S`?
| constructor is not visible here due to private fields
| did you mean `Z { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope
|
Expand All @@ -19,8 +19,8 @@ error[E0423]: expected value, found struct `S`
36 | S;
| ^
| |
| did you mean `S { /* fields */ }`?
| constructor is not visible here due to private fields
| did you mean `S { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope
|
Expand All @@ -33,8 +33,8 @@ error[E0423]: expected value, found struct `xcrate::S`
42 | xcrate::S;
| ^^^^^^^^^
| |
| did you mean `xcrate::S { /* fields */ }`?
| constructor is not visible here due to private fields
| did you mean `xcrate::S { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/unresolved_static_type_field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0425]: cannot find value `cx` in this scope
19 | f(cx);
| ^^
| |
| help: try: `self.cx`
| `self` value is only available in methods with `self` parameter
| help: try: `self.cx`

error: aborting due to previous error

8 changes: 4 additions & 4 deletions src/test/ui/type-check/assignment-in-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0308]: mismatched types
25 | if x = x {
| ^^^^^
| |
| help: did you mean to compare equality?: `x == x`
| expected bool, found ()
| help: did you mean to compare equality?: `x == x`
|
= note: expected type `bool`
found type `()`
Expand All @@ -16,8 +16,8 @@ error[E0308]: mismatched types
31 | if (x = x) {
| ^^^^^^^
| |
| help: did you mean to compare equality?: `x == x`
| expected bool, found ()
| help: did you mean to compare equality?: `x == x`
|
= note: expected type `bool`
found type `()`
Expand All @@ -28,8 +28,8 @@ error[E0308]: mismatched types
37 | if y = (Foo { foo: x }) {
| ^^^^^^^^^^^^^^^^^^^^
| |
| help: did you mean to compare equality?: `y == (Foo { foo: x })`
| expected bool, found ()
| help: did you mean to compare equality?: `y == (Foo { foo: x })`
|
= note: expected type `bool`
found type `()`
Expand All @@ -40,8 +40,8 @@ error[E0308]: mismatched types
43 | if 3 = x {
| ^^^^^
| |
| help: did you mean to compare equality?: `3 == x`
| expected bool, found ()
| help: did you mean to compare equality?: `3 == x`
|
= note: expected type `bool`
found type `()`
Expand Down

0 comments on commit 26a8357

Please sign in to comment.