@@ -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| {
@@ -1190,13 +1181,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1190
1181
if !tcx. sess . source_map ( ) . is_span_accessible ( span) {
1191
1182
continue ;
1192
1183
}
1184
+ let pre = if Some ( span) == ty_span {
1185
+ ty_span. take ( ) ;
1186
+ format ! (
1187
+ "{item_kind} `{item_name}` not found for this {} because it " ,
1188
+ rcvr_ty. prefix_string( self . tcx)
1189
+ )
1190
+ } else {
1191
+ String :: new ( )
1192
+ } ;
1193
1193
let msg = match & bounds[ ..] {
1194
- [ bound] => format ! ( "doesn't satisfy {bound}" ) ,
1195
- [ bounds @ .., last] => format ! ( "doesn't satisfy {} or {last}" , bounds. join( ", " ) ) ,
1194
+ [ bound] => format ! ( "{pre}doesn't satisfy {bound}" ) ,
1195
+ [ bounds @ .., last] => {
1196
+ format ! ( "{pre}doesn't satisfy {} or {last}" , bounds. join( ", " ) )
1197
+ }
1196
1198
[ ] => unreachable ! ( ) ,
1197
1199
} ;
1198
1200
err. span_label ( span, msg) ;
1199
1201
}
1202
+ if let Some ( span) = ty_span {
1203
+ err. span_label (
1204
+ span,
1205
+ format ! (
1206
+ "{item_kind} `{item_name}` not found for this {}" ,
1207
+ rcvr_ty. prefix_string( self . tcx)
1208
+ ) ,
1209
+ ) ;
1210
+ }
1200
1211
1201
1212
if rcvr_ty. is_numeric ( ) && rcvr_ty. is_fresh ( ) || restrict_type_params {
1202
1213
} else {
0 commit comments