Skip to content

Commit 64ed233

Browse files
authored
Rollup merge of #116908 - estebank:issue-78206, r=compiler-errors
Tweak wording of type errors involving type params Fix #78206.
2 parents 42c7d21 + bd8b468 commit 64ed233

31 files changed

+72
-55
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
8585
{
8686
let p_def_id = tcx.generics_of(body_owner_def_id).type_param(p, tcx).def_id;
8787
let p_span = tcx.def_span(p_def_id);
88+
let expected = match (values.expected.kind(), values.found.kind()) {
89+
(ty::Param(_), _) => "expected ",
90+
(_, ty::Param(_)) => "found ",
91+
_ => "",
92+
};
8893
if !sp.contains(p_span) {
89-
diag.span_label(p_span, "this type parameter");
94+
diag.span_label(p_span, format!("{expected}this type parameter"));
9095
}
9196
let hir = tcx.hir();
9297
let mut note = true;
@@ -168,8 +173,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
168173
| (ty::Dynamic(..) | ty::Alias(ty::Opaque, ..), ty::Param(p)) => {
169174
let generics = tcx.generics_of(body_owner_def_id);
170175
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
176+
let expected = match (values.expected.kind(), values.found.kind()) {
177+
(ty::Param(_), _) => "expected ",
178+
(_, ty::Param(_)) => "found ",
179+
_ => "",
180+
};
171181
if !sp.contains(p_span) {
172-
diag.span_label(p_span, "this type parameter");
182+
diag.span_label(p_span, format!("{expected}this type parameter"));
173183
}
174184
diag.help("type parameters must be constrained to match other types");
175185
if tcx.sess.teach(&diag.get_code().unwrap()) {
@@ -209,7 +219,7 @@ impl<T> Trait<T> for X {
209219
let generics = tcx.generics_of(body_owner_def_id);
210220
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
211221
if !sp.contains(p_span) {
212-
diag.span_label(p_span, "this type parameter");
222+
diag.span_label(p_span, "expected this type parameter");
213223
}
214224
diag.help(format!(
215225
"every closure has a distinct type and so could not always match the \
@@ -219,8 +229,13 @@ impl<T> Trait<T> for X {
219229
(ty::Param(p), _) | (_, ty::Param(p)) => {
220230
let generics = tcx.generics_of(body_owner_def_id);
221231
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
232+
let expected = match (values.expected.kind(), values.found.kind()) {
233+
(ty::Param(_), _) => "expected ",
234+
(_, ty::Param(_)) => "found ",
235+
_ => "",
236+
};
222237
if !sp.contains(p_span) {
223-
diag.span_label(p_span, "this type parameter");
238+
diag.span_label(p_span, format!("{expected}this type parameter"));
224239
}
225240
}
226241
(ty::Alias(ty::Projection | ty::Inherent, proj_ty), _)

src/tools/clippy/tests/ui/builtin_type_shadow.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error[E0308]: mismatched types
1313
LL | fn foo<u32>(a: u32) -> u32 {
1414
| --- --- expected `u32` because of return type
1515
| |
16-
| this type parameter
16+
| expected this type parameter
1717
LL | 42
1818
| ^^ expected type parameter `u32`, found integer
1919
|

tests/ui/associated-type-bounds/elision.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()>
1717
| ----------------------------- -------------- ^^^^^^^^ expected `Option<&()>`, found `Option<impl Iterator<Item = &'_ ()>>`
1818
| | |
1919
| | expected `Option<&()>` because of return type
20-
| this type parameter
20+
| found this type parameter
2121
|
2222
= note: expected enum `Option<&()>`
2323
found enum `Option<impl Iterator<Item = &'_ ()>>`

tests/ui/associated-types/associated-types-issue-20346.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<
22
--> $DIR/associated-types-issue-20346.rs:34:36
33
|
44
LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
5-
| - this type parameter
5+
| - found this type parameter
66
...
77
LL | is_iterator_of::<Option<T>, _>(&adapter);
88
| ------------------------------ ^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`

tests/ui/associated-types/hr-associated-type-projection-1.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0271]: type mismatch resolving `<T as Deref>::Target == T`
22
--> $DIR/hr-associated-type-projection-1.rs:13:33
33
|
44
LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T {
5-
| - this type parameter ^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type
5+
| - ^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type
6+
| |
7+
| expected this type parameter
68
|
79
= note: expected type parameter `T`
810
found associated type `<T as Deref>::Target`

tests/ui/const-generics/issues/issue-67945-1.full.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-67945-1.rs:10:20
33
|
44
LL | struct Bug<S> {
5-
| - this type parameter
5+
| - expected this type parameter
66
...
77
LL | let x: S = MaybeUninit::uninit();
88
| - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found `MaybeUninit<_>`

tests/ui/generic-associated-types/issue-68648-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-68648-2.rs:12:17
33
|
44
LL | fn bug<'a, T: Fun<F<'a> = T>>(t: T) -> T::F<'a> {
5-
| - this type parameter
5+
| - expected this type parameter
66
LL | T::identity(())
77
| ----------- ^^ expected type parameter `T`, found `()`
88
| |

tests/ui/generic-associated-types/issue-68656-unsized-values.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<T as Deref>::Target == T`
22
--> $DIR/issue-68656-unsized-values.rs:13:21
33
|
44
LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<T> for T {
5-
| - this type parameter
5+
| - expected this type parameter
66
LL | type Item<'a> = T;
77
| ^ expected type parameter `T`, found associated type
88
|

tests/ui/generic-associated-types/issue-88360.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-88360.rs:15:9
33
|
44
LL | trait SuperTrait<T>
5-
| - this type parameter
5+
| - found this type parameter
66
...
77
LL | fn copy(&self) -> Self::Gat<'_> where T: Copy {
88
| ------------- expected `&T` because of return type

tests/ui/generic-associated-types/missing-bounds.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0308]: mismatched types
1414
--> $DIR/missing-bounds.rs:11:11
1515
|
1616
LL | impl<B> Add for A<B> where B: Add {
17-
| - this type parameter
17+
| - expected this type parameter
1818
...
1919
LL | A(self.0 + rhs.0)
2020
| - ^^^^^^^^^^^^^^ expected type parameter `B`, found associated type
@@ -44,7 +44,7 @@ error[E0308]: mismatched types
4444
--> $DIR/missing-bounds.rs:21:14
4545
|
4646
LL | impl<B: Add> Add for C<B> {
47-
| - this type parameter
47+
| - expected this type parameter
4848
...
4949
LL | Self(self.0 + rhs.0)
5050
| ---- ^^^^^^^^^^^^^^ expected type parameter `B`, found associated type
@@ -80,7 +80,7 @@ error[E0308]: mismatched types
8080
--> $DIR/missing-bounds.rs:42:14
8181
|
8282
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
83-
| - this type parameter
83+
| - expected this type parameter
8484
...
8585
LL | Self(self.0 + rhs.0)
8686
| ---- ^^^^^^^^^^^^^^ expected type parameter `B`, found associated type

0 commit comments

Comments
 (0)