diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 3e8bd093f4f93..ad2562e28fa4f 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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. // diff --git a/src/test/ui/did_you_mean/issue-31424.stderr b/src/test/ui/did_you_mean/issue-31424.stderr index c7d43a0fc0b6f..023f9ef1defb7 100644 --- a/src/test/ui/did_you_mean/issue-31424.stderr +++ b/src/test/ui/did_you_mean/issue-31424.stderr @@ -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 diff --git a/src/test/ui/did_you_mean/issue-34126.stderr b/src/test/ui/did_you_mean/issue-34126.stderr index 63d59a59238b5..d9ef0c4541041 100644 --- a/src/test/ui/did_you_mean/issue-34126.stderr +++ b/src/test/ui/did_you_mean/issue-34126.stderr @@ -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 diff --git a/src/test/ui/did_you_mean/issue-34337.stderr b/src/test/ui/did_you_mean/issue-34337.stderr index 9eb88cdeddbe6..20478165c7ea0 100644 --- a/src/test/ui/did_you_mean/issue-34337.stderr +++ b/src/test/ui/did_you_mean/issue-34337.stderr @@ -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 diff --git a/src/test/ui/did_you_mean/issue-37139.stderr b/src/test/ui/did_you_mean/issue-37139.stderr index 4348b6fca63b6..9fc364f861275 100644 --- a/src/test/ui/did_you_mean/issue-37139.stderr +++ b/src/test/ui/did_you_mean/issue-37139.stderr @@ -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 diff --git a/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr b/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr index 26f150811b7db..56d0a5351ce83 100644 --- a/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr +++ b/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr @@ -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 diff --git a/src/test/ui/mismatched_types/E0281.stderr b/src/test/ui/mismatched_types/E0281.stderr index 887412d1be7af..744e8c3093925 100644 --- a/src/test/ui/mismatched_types/E0281.stderr +++ b/src/test/ui/mismatched_types/E0281.stderr @@ -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` diff --git a/src/test/ui/mismatched_types/closure-mismatch.stderr b/src/test/ui/mismatched_types/closure-mismatch.stderr index 5b3eb5931896a..b7479f15b1812 100644 --- a/src/test/ui/mismatched_types/closure-mismatch.stderr +++ b/src/test/ui/mismatched_types/closure-mismatch.stderr @@ -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` diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index 51acdb719b69a..174f7dfa0d0f5 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -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 diff --git a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr index 995a125845477..f14e711b23a1e 100644 --- a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr +++ b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr @@ -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` diff --git a/src/test/ui/resolve/issue-2356.stderr b/src/test/ui/resolve/issue-2356.stderr index 9c683f4418972..ed0edd52587ec 100644 --- a/src/test/ui/resolve/issue-2356.stderr +++ b/src/test/ui/resolve/issue-2356.stderr @@ -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 @@ -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 diff --git a/src/test/ui/resolve/issue-5035.stderr b/src/test/ui/resolve/issue-5035.stderr index 19adecc7b4bd2..3c093e068c507 100644 --- a/src/test/ui/resolve/issue-5035.stderr +++ b/src/test/ui/resolve/issue-5035.stderr @@ -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 diff --git a/src/test/ui/resolve/privacy-struct-ctor.stderr b/src/test/ui/resolve/privacy-struct-ctor.stderr index 57b143d34dbd2..47141eda33c55 100644 --- a/src/test/ui/resolve/privacy-struct-ctor.stderr +++ b/src/test/ui/resolve/privacy-struct-ctor.stderr @@ -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 | @@ -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 | @@ -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 | diff --git a/src/test/ui/resolve/unresolved_static_type_field.stderr b/src/test/ui/resolve/unresolved_static_type_field.stderr index e598851e3628e..014e03eb252be 100644 --- a/src/test/ui/resolve/unresolved_static_type_field.stderr +++ b/src/test/ui/resolve/unresolved_static_type_field.stderr @@ -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 diff --git a/src/test/ui/type-check/assignment-in-if.stderr b/src/test/ui/type-check/assignment-in-if.stderr index b740a1b776f75..4b8a3744bcf8a 100644 --- a/src/test/ui/type-check/assignment-in-if.stderr +++ b/src/test/ui/type-check/assignment-in-if.stderr @@ -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 `()` @@ -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 `()` @@ -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 `()` @@ -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 `()`