@@ -459,22 +459,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
459459 ) ;
460460 }
461461
462- let ty_span = match rcvr_ty. kind ( ) {
462+ let mut ty_span = match rcvr_ty. kind ( ) {
463463 ty:: Param ( param_type) => {
464464 Some ( param_type. span_from_generics ( self . tcx , self . body_id . to_def_id ( ) ) )
465465 }
466466 ty:: Adt ( def, _) if def. did ( ) . is_local ( ) => Some ( tcx. def_span ( def. did ( ) ) ) ,
467467 _ => None ,
468468 } ;
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- }
478469
479470 if let SelfSource :: MethodCall ( rcvr_expr) = source {
480471 self . suggest_fn_call ( & mut err, rcvr_expr, rcvr_ty, |output_ty| {
@@ -1201,13 +1192,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12011192 if !tcx. sess . source_map ( ) . is_span_accessible ( span) {
12021193 continue ;
12031194 }
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+ } ;
12041204 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+ }
12071209 [ ] => unreachable ! ( ) ,
12081210 } ;
12091211 err. span_label ( span, msg) ;
12101212 }
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+ }
12111222
12121223 if rcvr_ty. is_numeric ( ) && rcvr_ty. is_fresh ( ) || restrict_type_params {
12131224 } else {
0 commit comments