@@ -85,8 +85,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
85
85
{
86
86
let p_def_id = tcx. generics_of ( body_owner_def_id) . type_param ( p, tcx) . def_id ;
87
87
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
+ } ;
88
93
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") ) ;
90
95
}
91
96
let hir = tcx. hir ( ) ;
92
97
let mut note = true ;
@@ -168,8 +173,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
168
173
| ( ty:: Dynamic ( ..) | ty:: Alias ( ty:: Opaque , ..) , ty:: Param ( p) ) => {
169
174
let generics = tcx. generics_of ( body_owner_def_id) ;
170
175
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
+ } ;
171
181
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") ) ;
173
183
}
174
184
diag. help ( "type parameters must be constrained to match other types" ) ;
175
185
if tcx. sess . teach ( & diag. get_code ( ) . unwrap ( ) ) {
@@ -209,7 +219,7 @@ impl<T> Trait<T> for X {
209
219
let generics = tcx. generics_of ( body_owner_def_id) ;
210
220
let p_span = tcx. def_span ( generics. type_param ( p, tcx) . def_id ) ;
211
221
if !sp. contains ( p_span) {
212
- diag. span_label ( p_span, "this type parameter" ) ;
222
+ diag. span_label ( p_span, "expected this type parameter" ) ;
213
223
}
214
224
diag. help ( format ! (
215
225
"every closure has a distinct type and so could not always match the \
@@ -219,8 +229,13 @@ impl<T> Trait<T> for X {
219
229
( ty:: Param ( p) , _) | ( _, ty:: Param ( p) ) => {
220
230
let generics = tcx. generics_of ( body_owner_def_id) ;
221
231
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
+ } ;
222
237
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") ) ;
224
239
}
225
240
}
226
241
( ty:: Alias ( ty:: Projection | ty:: Inherent , proj_ty) , _)
0 commit comments