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

Lines changed: 13 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)