@@ -278,9 +278,8 @@ fn compare_predicate_entailment<'tcx>(
278278 if let Err ( terr) = sub_result {
279279 debug ! ( "sub_types failed: impl ty {:?}, trait ty {:?}" , impl_fty, trait_fty) ;
280280
281- let ( impl_err_span, trait_err_span) = extract_spans_for_error_reporting (
282- & infcx, param_env, & terr, & cause, impl_m, impl_sig, trait_m, trait_sig,
283- ) ;
281+ let ( impl_err_span, trait_err_span) =
282+ extract_spans_for_error_reporting ( & infcx, & terr, & cause, impl_m, trait_m) ;
284283
285284 cause. make_mut ( ) . span = impl_err_span;
286285
@@ -291,7 +290,7 @@ fn compare_predicate_entailment<'tcx>(
291290 "method `{}` has an incompatible type for trait" ,
292291 trait_m. ident
293292 ) ;
294- if let TypeError :: Mutability = terr {
293+ if let TypeError :: ArgumentMutability ( _ ) = terr {
295294 if let Some ( trait_err_span) = trait_err_span {
296295 if let Ok ( trait_err_str) = tcx. sess . source_map ( ) . span_to_snippet ( trait_err_span)
297296 {
@@ -385,86 +384,35 @@ fn check_region_bounds_on_impl_item<'tcx>(
385384
386385fn extract_spans_for_error_reporting < ' a , ' tcx > (
387386 infcx : & infer:: InferCtxt < ' a , ' tcx > ,
388- param_env : ty:: ParamEnv < ' tcx > ,
389387 terr : & TypeError < ' _ > ,
390388 cause : & ObligationCause < ' tcx > ,
391389 impl_m : & ty:: AssocItem ,
392- impl_sig : ty:: FnSig < ' tcx > ,
393390 trait_m : & ty:: AssocItem ,
394- trait_sig : ty:: FnSig < ' tcx > ,
395391) -> ( Span , Option < Span > ) {
396392 let tcx = infcx. tcx ;
397393 let impl_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( impl_m. def_id . expect_local ( ) ) ;
398- let ( impl_m_output , impl_m_iter ) = match tcx. hir ( ) . expect_impl_item ( impl_m_hir_id) . kind {
399- ImplItemKind :: Fn ( ref impl_m_sig , _) => {
400- ( & impl_m_sig . decl . output , impl_m_sig . decl . inputs . iter ( ) )
394+ let mut impl_args = match tcx. hir ( ) . expect_impl_item ( impl_m_hir_id) . kind {
395+ ImplItemKind :: Fn ( ref sig , _) => {
396+ sig . decl . inputs . iter ( ) . map ( |t| t . span ) . chain ( iter :: once ( sig . decl . output . span ( ) ) )
401397 }
402398 _ => bug ! ( "{:?} is not a method" , impl_m) ,
403399 } ;
400+ let trait_args = trait_m. def_id . as_local ( ) . map ( |def_id| {
401+ let trait_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
402+ match tcx. hir ( ) . expect_trait_item ( trait_m_hir_id) . kind {
403+ TraitItemKind :: Fn ( ref sig, _) => {
404+ sig. decl . inputs . iter ( ) . map ( |t| t. span ) . chain ( iter:: once ( sig. decl . output . span ( ) ) )
405+ }
406+ _ => bug ! ( "{:?} is not a TraitItemKind::Fn" , trait_m) ,
407+ }
408+ } ) ;
404409
405410 match * terr {
406- TypeError :: Mutability => {
407- if let Some ( def_id) = trait_m. def_id . as_local ( ) {
408- let trait_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
409- let trait_m_iter = match tcx. hir ( ) . expect_trait_item ( trait_m_hir_id) . kind {
410- TraitItemKind :: Fn ( ref trait_m_sig, _) => trait_m_sig. decl . inputs . iter ( ) ,
411- _ => bug ! ( "{:?} is not a TraitItemKind::Fn" , trait_m) ,
412- } ;
413-
414- iter:: zip ( impl_m_iter, trait_m_iter)
415- . find ( |& ( ref impl_arg, ref trait_arg) | {
416- match ( & impl_arg. kind , & trait_arg. kind ) {
417- (
418- & hir:: TyKind :: Rptr ( _, ref impl_mt) ,
419- & hir:: TyKind :: Rptr ( _, ref trait_mt) ,
420- )
421- | ( & hir:: TyKind :: Ptr ( ref impl_mt) , & hir:: TyKind :: Ptr ( ref trait_mt) ) => {
422- impl_mt. mutbl != trait_mt. mutbl
423- }
424- _ => false ,
425- }
426- } )
427- . map ( |( ref impl_arg, ref trait_arg) | ( impl_arg. span , Some ( trait_arg. span ) ) )
428- . unwrap_or_else ( || ( cause. span ( tcx) , tcx. hir ( ) . span_if_local ( trait_m. def_id ) ) )
429- } else {
430- ( cause. span ( tcx) , tcx. hir ( ) . span_if_local ( trait_m. def_id ) )
431- }
411+ TypeError :: ArgumentMutability ( i) => {
412+ ( impl_args. nth ( i) . unwrap ( ) , trait_args. and_then ( |mut args| args. nth ( i) ) )
432413 }
433- TypeError :: Sorts ( ExpectedFound { .. } ) => {
434- if let Some ( def_id) = trait_m. def_id . as_local ( ) {
435- let trait_m_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
436- let ( trait_m_output, trait_m_iter) =
437- match tcx. hir ( ) . expect_trait_item ( trait_m_hir_id) . kind {
438- TraitItemKind :: Fn ( ref trait_m_sig, _) => {
439- ( & trait_m_sig. decl . output , trait_m_sig. decl . inputs . iter ( ) )
440- }
441- _ => bug ! ( "{:?} is not a TraitItemKind::Fn" , trait_m) ,
442- } ;
443-
444- let impl_iter = impl_sig. inputs ( ) . iter ( ) ;
445- let trait_iter = trait_sig. inputs ( ) . iter ( ) ;
446- iter:: zip ( iter:: zip ( impl_iter, trait_iter) , iter:: zip ( impl_m_iter, trait_m_iter) )
447- . find_map ( |( ( & impl_arg_ty, & trait_arg_ty) , ( impl_arg, trait_arg) ) | match infcx
448- . at ( & cause, param_env)
449- . sub ( trait_arg_ty, impl_arg_ty)
450- {
451- Ok ( _) => None ,
452- Err ( _) => Some ( ( impl_arg. span , Some ( trait_arg. span ) ) ) ,
453- } )
454- . unwrap_or_else ( || {
455- if infcx
456- . at ( & cause, param_env)
457- . sup ( trait_sig. output ( ) , impl_sig. output ( ) )
458- . is_err ( )
459- {
460- ( impl_m_output. span ( ) , Some ( trait_m_output. span ( ) ) )
461- } else {
462- ( cause. span ( tcx) , tcx. hir ( ) . span_if_local ( trait_m. def_id ) )
463- }
464- } )
465- } else {
466- ( cause. span ( tcx) , tcx. hir ( ) . span_if_local ( trait_m. def_id ) )
467- }
414+ TypeError :: ArgumentSorts ( ExpectedFound { .. } , i) => {
415+ ( impl_args. nth ( i) . unwrap ( ) , trait_args. and_then ( |mut args| args. nth ( i) ) )
468416 }
469417 _ => ( cause. span ( tcx) , tcx. hir ( ) . span_if_local ( trait_m. def_id ) ) ,
470418 }
@@ -514,8 +462,7 @@ fn compare_self_type<'tcx>(
514462 tcx. sess,
515463 impl_m_span,
516464 E0185 ,
517- "method `{}` has a `{}` declaration in the impl, but \
518- not in the trait",
465+ "method `{}` has a `{}` declaration in the impl, but not in the trait" ,
519466 trait_m. ident,
520467 self_descr
521468 ) ;
@@ -993,8 +940,7 @@ crate fn compare_const_impl<'tcx>(
993940 tcx. sess,
994941 cause. span,
995942 E0326 ,
996- "implemented const `{}` has an incompatible type for \
997- trait",
943+ "implemented const `{}` has an incompatible type for trait" ,
998944 trait_c. ident
999945 ) ;
1000946
0 commit comments