@@ -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| {
@@ -1190,13 +1181,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11901181 if !tcx. sess . source_map ( ) . is_span_accessible ( span) {
11911182 continue ;
11921183 }
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+ } ;
11931193 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+ }
11961198 [ ] => unreachable ! ( ) ,
11971199 } ;
11981200 err. span_label ( span, msg) ;
11991201 }
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+ }
12001211
12011212 if rcvr_ty. is_numeric ( ) && rcvr_ty. is_fresh ( ) || restrict_type_params {
12021213 } else {
0 commit comments