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`

src/test/ui/generic-associated-types/issue-74684-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]`
1111
--> $DIR/issue-74684-2.rs:24:5
1212
|
1313
LL | type F<'a> = i32;
14-
| --- expected slice `[u8]`, found `i32`
14+
| --- expected this to be `[u8]`
1515
...
1616
LL | fn bug<'a, T: ?Sized + Fun<F<'a> = [u8]>>(t: Box<T>) -> &'static T::F<'a> {
1717
| ------------ required by this bound in `bug`

src/test/ui/hrtb/issue-62203-hrtb-ice.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb
22
--> $DIR/issue-62203-hrtb-ice.rs:38:19
33
|
44
LL | type O = T::Output;
5-
| --------- expected struct `Unit4`, found associated type
5+
| --------- expected this to be `Unit4`
66
...
77
LL | let v = Unit2.m(
88
| ^ type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]> as T0<'r, (<Unit2 as Ty<'r>>::V,)>>::O == <_ as Ty<'r>>::V`

src/test/ui/impl-trait/bound-normalization-fail.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as imp
1111
--> $DIR/bound-normalization-fail.rs:26:32
1212
|
1313
LL | type Output = T;
14-
| - expected associated type, found `()`
14+
| - expected this to be `<T as impl_trait::Trait>::Assoc`
1515
...
1616
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> {
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
@@ -33,7 +33,7 @@ error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lif
3333
--> $DIR/bound-normalization-fail.rs:42:41
3434
|
3535
LL | type Output = T;
36-
| - expected associated type, found `()`
36+
| - expected this to be `<T as lifetimes::Trait<'static>>::Assoc`
3737
...
3838
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> {
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`

src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()`
22
--> $DIR/projection-mismatch-in-impl-where-clause.rs:13:14
33
|
44
LL | type Assoc = u8;
5-
| -- expected `()`, found `u8`
5+
| -- expected this to be `()`
66
...
77
LL | fn test() -> impl Test {
88
| ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()`

src/test/ui/issues/issue-39970.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 = &'a ();
8-
| ------ expected `()`, found `&()`
8+
| ------ expected this to be `()`
99
...
1010
LL | <() as Visit>::visit();
1111
| ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'a> <() as Array<'a>>::Element == ()`

src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<i32 as Is>::T == i64`
22
--> $DIR/check-trait-object-bounds-5.rs:23:5
33
|
44
LL | type T = U;
5-
| - expected `i64`, found `i32`
5+
| - expected this to be `i64`
66
...
77
LL | fn is_obj<T: ?Sized + Obj>(_: &T) {}
88
| --- required by this bound in `is_obj`

src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<i32 as Is>::T == i64`
22
--> $DIR/check-trait-object-bounds-6.rs:20:5
33
|
44
LL | type T = U;
5-
| - expected `i64`, found `i32`
5+
| - expected this to be `i64`
66
...
77
LL | fn is_obj<T: ?Sized + Obj>(_: &T) {}
88
| --- required by this bound in `is_obj`

0 commit comments

Comments
 (0)