Skip to content

Commit 6a5b476

Browse files
committed
Further tweak labels
1 parent 0ced102 commit 6a5b476

17 files changed

+31
-24
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15851585
_ => {
15861586
if let Some((sp, msg)) = secondary_span {
15871587
if swap_secondary_and_primary {
1588-
diag.span_label(sp, terr.to_string());
1588+
let terr = if let Some(infer::ValuePairs::Types(infer::ExpectedFound {
1589+
expected,
1590+
..
1591+
})) = values
1592+
{
1593+
format!("expected this to be `{}`", expected)
1594+
} else {
1595+
terr.to_string()
1596+
};
1597+
diag.span_label(sp, terr);
15891598
diag.span_label(span, msg);
15901599
} else {
15911600
diag.span_label(span, terr.to_string());

compiler/rustc_middle/src/ty/error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,15 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
115115
ArgumentMutability(_) | Mutability => write!(f, "types differ in mutability"),
116116
TupleSize(values) => write!(
117117
f,
118-
"expected a tuple with {} element{}, \
119-
found one with {} element{}",
118+
"expected a tuple with {} element{}, found one with {} element{}",
120119
values.expected,
121120
pluralize!(values.expected),
122121
values.found,
123122
pluralize!(values.found)
124123
),
125124
FixedArraySize(values) => write!(
126125
f,
127-
"expected an array with a fixed size of {} element{}, \
128-
found one with {} element{}",
126+
"expected an array with a fixed size of {} element{}, found one with {} element{}",
129127
values.expected,
130128
pluralize!(values.expected),
131129
values.found,

src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
22
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10
33
|
44
LL | impl Vehicle for ModelT { type Color = Black; }
5-
| ----- expected struct `Blue`, found struct `Black`
5+
| ----- expected this to be `Blue`
66
...
77
LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
88
| ---------- required by this bound in `blue_car`
@@ -14,7 +14,7 @@ error[E0271]: type mismatch resolving `<ModelU as Vehicle>::Color == Black`
1414
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10
1515
|
1616
LL | impl Vehicle for ModelU { type Color = Blue; }
17-
| ---- expected struct `Black`, found struct `Blue`
17+
| ---- expected this to be `Black`
1818
...
1919
LL | fn black_car<C:Car<Color=Black>>(c: C) {
2020
| ----------- required by this bound in `black_car`

src/test/ui/associated-types/associated-types-eq-3.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
1717
--> $DIR/associated-types-eq-3.rs:38:5
1818
|
1919
LL | type A = usize;
20-
| ----- expected struct `Bar`, found `usize`
20+
| ----- expected this to be `Bar`
2121
...
2222
LL | fn foo1<I: Foo<A=Bar>>(x: I) {
2323
| ----- required by this bound in `foo1`
@@ -29,7 +29,7 @@ error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
2929
--> $DIR/associated-types-eq-3.rs:40:9
3030
|
3131
LL | type A = usize;
32-
| ----- expected struct `Bar`, found `usize`
32+
| ----- expected this to be `Bar`
3333
...
3434
LL | baz(&a);
3535
| ^^ type mismatch resolving `<isize as Foo>::A == Bar`

src/test/ui/associated-types/associated-types-eq-hr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize
22
--> $DIR/associated-types-eq-hr.rs:87:5
33
|
44
LL | type A = &'a usize;
5-
| --------- expected `isize`, found `usize`
5+
| --------- expected this to be `&isize`
66
...
77
LL | fn foo<T>()
88
| --- required by a bound in this
@@ -20,7 +20,7 @@ error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>
2020
--> $DIR/associated-types-eq-hr.rs:91:5
2121
|
2222
LL | type A = &'a isize;
23-
| --------- expected `usize`, found `isize`
23+
| --------- expected this to be `&usize`
2424
...
2525
LL | fn bar<T>()
2626
| --- required by a bound in this

src/test/ui/associated-types/associated-types-issue-20346.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
55
| ------ required by this bound in `is_iterator_of`
66
...
77
LL | type Item = T;
8-
| - expected enum `Option`, found type parameter `T`
8+
| - expected this to be `Option<T>`
99
...
1010
LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
1111
| - this type parameter

src/test/ui/associated-types/issue-44153.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn visit() {}
55
| ---------- required by `Visit::visit`
66
...
77
LL | type Element = ();
8-
| -- expected `&()`, found `()`
8+
| -- expected this to be `&()`
99
...
1010
LL | <() as Visit>::visit();
1111
| ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array>::Element == &()`

src/test/ui/associated-types/issue-72806.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | type Sibling = Foo2;
88
| ^^^^ type mismatch resolving `<Foo2 as Bar2>::Ok == char`
99
...
1010
LL | type Ok = u32;
11-
| --- expected `char`, found `u32`
11+
| --- expected this to be `char`
1212

1313
error: aborting due to previous error
1414

src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | type Sibling = Foo2;
88
| ^^^^ type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
99
...
1010
LL | type Ok = u32;
11-
| --- expected `()`, found `u32`
11+
| --- expected this to be `()`
1212

1313
error: aborting due to previous error
1414

src/test/ui/error-codes/E0271.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
55
| ------------------ required by this bound in `foo`
66
...
77
LL | impl Trait for i8 { type AssociatedType = &'static str; }
8-
| ------------ expected `u32`, found `&str`
8+
| ------------ expected this to be `u32`
99
...
1010
LL | foo(3_i8);
1111
| ^^^ type mismatch resolving `<i8 as Trait>::AssociatedType == u32`

0 commit comments

Comments
 (0)