@@ -459,22 +459,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
459
459
) ;
460
460
}
461
461
462
- let ty_span = match rcvr_ty. kind ( ) {
462
+ let mut ty_span = match rcvr_ty. kind ( ) {
463
463
ty:: Param ( param_type) => {
464
464
Some ( param_type. span_from_generics ( self . tcx , self . body_id . to_def_id ( ) ) )
465
465
}
466
466
ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => Some ( tcx. def_span ( def. did ( ) ) ) ,
467
467
_ => None ,
468
468
} ;
469
- if let Some ( span) = ty_span {
470
- err. span_label (
471
- span,
472
- format ! (
473
- "{item_kind} `{item_name}` not found for this {}" ,
474
- rcvr_ty. prefix_string( self . tcx)
475
- ) ,
476
- ) ;
477
- }
478
469
479
470
if let SelfSource :: MethodCall ( rcvr_expr) = source {
480
471
self . suggest_fn_call ( & mut err, rcvr_expr, rcvr_ty, |output_ty| {
@@ -1201,13 +1192,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1201
1192
if !tcx. sess . source_map ( ) . is_span_accessible ( span) {
1202
1193
continue ;
1203
1194
}
1195
+ let pre = if Some ( span) == ty_span {
1196
+ ty_span. take ( ) ;
1197
+ format ! (
1198
+ "{item_kind} `{item_name}` not found for this {} because it " ,
1199
+ rcvr_ty. prefix_string( self . tcx)
1200
+ )
1201
+ } else {
1202
+ String :: new ( )
1203
+ } ;
1204
1204
let msg = match & bounds[ ..] {
1205
- [ bound] => format ! ( "doesn't satisfy {bound}" ) ,
1206
- [ bounds @ .., last] => format ! ( "doesn't satisfy {} or {last}" , bounds. join( ", " ) ) ,
1205
+ [ bound] => format ! ( "{pre}doesn't satisfy {bound}" ) ,
1206
+ [ bounds @ .., last] => {
1207
+ format ! ( "{pre}doesn't satisfy {} or {last}" , bounds. join( ", " ) )
1208
+ }
1207
1209
[ ] => unreachable ! ( ) ,
1208
1210
} ;
1209
1211
err. span_label ( span, msg) ;
1210
1212
}
1213
+ if let Some ( span) = ty_span {
1214
+ err. span_label (
1215
+ span,
1216
+ format ! (
1217
+ "{item_kind} `{item_name}` not found for this {}" ,
1218
+ rcvr_ty. prefix_string( self . tcx)
1219
+ ) ,
1220
+ ) ;
1221
+ }
1211
1222
1212
1223
if rcvr_ty. is_numeric ( ) && rcvr_ty. is_fresh ( ) || restrict_type_params {
1213
1224
} else {
0 commit comments