Skip to content

Commit 1beaea2

Browse files
committed
Auto merge of #43251 - gaurikholkar:span_reorder, r=nikomatsakis
Reorder span suggestions to appear below main labels A fix to #41698 r? @nikomatsakis
2 parents 28486e7 + 26a8357 commit 1beaea2

15 files changed

+33
-22
lines changed

src/librustc_errors/emitter.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,20 @@ impl EmitterWriter {
346346
// and "annotations lines", where the highlight lines have the `^`.
347347

348348
// Sort the annotations by (start, end col)
349+
// The labels are reversed, sort and then reversed again.
350+
// Consider a list of annotations (A1, A2, C1, C2, B1, B2) where
351+
// the letter signifies the span. Here we are only sorting by the
352+
// span and hence, the order of the elements with the same span will
353+
// not change. On reversing the ordering (|a, b| but b.cmp(a)), you get
354+
// (C1, C2, B1, B2, A1, A2). All the elements with the same span are
355+
// still ordered first to last, but all the elements with different
356+
// spans are ordered by their spans in last to first order. Last to
357+
// first order is important, because the jiggly lines and | are on
358+
// the left, so the rightmost span needs to be rendered first,
359+
// otherwise the lines would end up needing to go over a message.
360+
349361
let mut annotations = line.annotations.clone();
350-
annotations.sort();
351-
annotations.reverse();
362+
annotations.sort_by(|a,b| b.start_col.cmp(&a.start_col));
352363

353364
// First, figure out where each label will be positioned.
354365
//

src/test/ui/did_you_mean/issue-31424.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable argument `self` as mutable
44
17 | (&mut self).bar();
55
| ^^^^
66
| |
7-
| try removing `&mut` here
87
| cannot reborrow mutably
8+
| try removing `&mut` here
99

1010
error[E0596]: cannot borrow immutable argument `self` as mutable
1111
--> $DIR/issue-31424.rs:23:15

src/test/ui/did_you_mean/issue-34126.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable argument `self` as mutable
44
16 | self.run(&mut self);
55
| ^^^^
66
| |
7-
| try removing `&mut` here
87
| cannot reborrow mutably
8+
| try removing `&mut` here
99

1010
error: aborting due to previous error
1111

src/test/ui/did_you_mean/issue-34337.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable local variable `key` as mutable
44
16 | get(&mut key);
55
| ^^^
66
| |
7-
| try removing `&mut` here
87
| cannot reborrow mutably
8+
| try removing `&mut` here
99

1010
error: aborting due to previous error
1111

src/test/ui/did_you_mean/issue-37139.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0596]: cannot borrow immutable local variable `x` as mutable
44
22 | test(&mut x);
55
| ^
66
| |
7-
| try removing `&mut` here
87
| cannot reborrow mutably
8+
| try removing `&mut` here
99

1010
error: aborting due to previous error
1111

src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0507]: cannot move out of indexed content
44
19 | let e = f.v[0];
55
| ^^^^^^
66
| |
7-
| help: consider using a reference instead: `&f.v[0]`
87
| cannot move out of indexed content
8+
| help: consider using a reference instead: `&f.v[0]`
99

1010
error: aborting due to previous error
1111

src/test/ui/mismatched_types/E0281.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0281]: type mismatch: `[closure@$DIR/E0281.rs:14:9: 14:24]` implements th
44
14 | foo(|y: String| { });
55
| ^^^ --------------- implements `std::ops::Fn<(std::string::String,)>`
66
| |
7-
| requires `std::ops::Fn<(usize,)>`
87
| expected usize, found struct `std::string::String`
8+
| requires `std::ops::Fn<(usize,)>`
99
|
1010
= note: required by `foo`
1111

src/test/ui/mismatched_types/closure-mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ error[E0281]: type mismatch: `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]` im
1414
18 | baz(|_| ());
1515
| ^^^ ------ implements `std::ops::Fn<(_,)>`
1616
| |
17-
| requires `for<'r> std::ops::Fn<(&'r (),)>`
1817
| expected concrete lifetime, found bound lifetime parameter
18+
| requires `for<'r> std::ops::Fn<(&'r (),)>`
1919
|
2020
= note: required because of the requirements on the impl of `Foo` for `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]`
2121
= note: required by `baz`

src/test/ui/mismatched_types/issue-36053-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ error[E0281]: type mismatch: `[closure@$DIR/issue-36053-2.rs:17:39: 17:53]` impl
1414
17 | once::<&str>("str").fuse().filter(|a: &str| true).count();
1515
| ^^^^^^ -------------- implements `for<'r> std::ops::FnMut<(&'r str,)>`
1616
| |
17-
| requires `for<'r> std::ops::FnMut<(&'r &str,)>`
1817
| expected &str, found str
18+
| requires `for<'r> std::ops::FnMut<(&'r &str,)>`
1919

2020
error: aborting due to 2 previous errors
2121

src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ error[E0281]: type mismatch: `[closure@$DIR/unboxed-closures-vtable-mismatch.rs:
77
25 | let z = call_it(3, f);
88
| ^^^^^^^
99
| |
10-
| requires `std::ops::FnMut<(isize, isize)>`
1110
| expected isize, found usize
11+
| requires `std::ops::FnMut<(isize, isize)>`
1212
|
1313
= note: required by `call_it`
1414

src/test/ui/resolve/issue-2356.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ error[E0425]: cannot find value `whiskers` in this scope
2222
52 | whiskers -= other;
2323
| ^^^^^^^^
2424
| |
25-
| help: try: `self.whiskers`
2625
| `self` value is only available in methods with `self` parameter
26+
| help: try: `self.whiskers`
2727

2828
error[E0425]: cannot find function `shave` in this scope
2929
--> $DIR/issue-2356.rs:57:5
@@ -91,8 +91,8 @@ error[E0425]: cannot find value `whiskers` in this scope
9191
110 | whiskers = 4;
9292
| ^^^^^^^^
9393
| |
94-
| help: try: `self.whiskers`
9594
| `self` value is only available in methods with `self` parameter
95+
| help: try: `self.whiskers`
9696

9797
error[E0425]: cannot find function `purr_louder` in this scope
9898
--> $DIR/issue-2356.rs:115:5

src/test/ui/resolve/issue-5035.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ error[E0404]: expected trait, found type alias `K`
1010
13 | impl K for isize {} //~ ERROR expected trait, found type alias `K`
1111
| ^
1212
| |
13-
| type aliases cannot be used for traits
1413
| did you mean `I`?
14+
| type aliases cannot be used for traits
1515

1616
error: cannot continue compilation due to previous error
1717

src/test/ui/resolve/privacy-struct-ctor.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ error[E0423]: expected value, found struct `Z`
44
26 | Z;
55
| ^
66
| |
7-
| did you mean `Z { /* fields */ }`?
87
| did you mean `S`?
98
| constructor is not visible here due to private fields
9+
| did you mean `Z { /* fields */ }`?
1010
|
1111
help: possible better candidate is found in another module, you can import it into scope
1212
|
@@ -19,8 +19,8 @@ error[E0423]: expected value, found struct `S`
1919
36 | S;
2020
| ^
2121
| |
22-
| did you mean `S { /* fields */ }`?
2322
| constructor is not visible here due to private fields
23+
| did you mean `S { /* fields */ }`?
2424
|
2525
help: possible better candidate is found in another module, you can import it into scope
2626
|
@@ -33,8 +33,8 @@ error[E0423]: expected value, found struct `xcrate::S`
3333
42 | xcrate::S;
3434
| ^^^^^^^^^
3535
| |
36-
| did you mean `xcrate::S { /* fields */ }`?
3736
| constructor is not visible here due to private fields
37+
| did you mean `xcrate::S { /* fields */ }`?
3838
|
3939
help: possible better candidate is found in another module, you can import it into scope
4040
|

src/test/ui/resolve/unresolved_static_type_field.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0425]: cannot find value `cx` in this scope
44
19 | f(cx);
55
| ^^
66
| |
7-
| help: try: `self.cx`
87
| `self` value is only available in methods with `self` parameter
8+
| help: try: `self.cx`
99

1010
error: aborting due to previous error
1111

src/test/ui/type-check/assignment-in-if.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
25 | if x = x {
55
| ^^^^^
66
| |
7-
| help: did you mean to compare equality?: `x == x`
87
| expected bool, found ()
8+
| help: did you mean to compare equality?: `x == x`
99
|
1010
= note: expected type `bool`
1111
found type `()`
@@ -16,8 +16,8 @@ error[E0308]: mismatched types
1616
31 | if (x = x) {
1717
| ^^^^^^^
1818
| |
19-
| help: did you mean to compare equality?: `x == x`
2019
| expected bool, found ()
20+
| help: did you mean to compare equality?: `x == x`
2121
|
2222
= note: expected type `bool`
2323
found type `()`
@@ -28,8 +28,8 @@ error[E0308]: mismatched types
2828
37 | if y = (Foo { foo: x }) {
2929
| ^^^^^^^^^^^^^^^^^^^^
3030
| |
31-
| help: did you mean to compare equality?: `y == (Foo { foo: x })`
3231
| expected bool, found ()
32+
| help: did you mean to compare equality?: `y == (Foo { foo: x })`
3333
|
3434
= note: expected type `bool`
3535
found type `()`
@@ -40,8 +40,8 @@ error[E0308]: mismatched types
4040
43 | if 3 = x {
4141
| ^^^^^
4242
| |
43-
| help: did you mean to compare equality?: `3 == x`
4443
| expected bool, found ()
44+
| help: did you mean to compare equality?: `3 == x`
4545
|
4646
= note: expected type `bool`
4747
found type `()`

0 commit comments

Comments
 (0)