@@ -40,6 +40,8 @@ pub fn compare_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4040 debug ! ( "compare_impl_method(impl_trait_ref={:?})" ,
4141 impl_trait_ref) ;
4242
43+ let impl_m_span = tcx. sess . codemap ( ) . def_span ( impl_m_span) ;
44+
4345 if let Err ( ErrorReported ) = compare_self_type ( tcx,
4446 impl_m,
4547 impl_m_span,
@@ -186,6 +188,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
186188 check_region_bounds_on_impl_method ( tcx,
187189 impl_m_span,
188190 impl_m,
191+ trait_m,
189192 & trait_m_generics,
190193 & impl_m_generics,
191194 trait_to_skol_substs) ?;
@@ -310,7 +313,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
310313 } ;
311314
312315 let mut diag = struct_span_err ! ( tcx. sess,
313- cause. span,
316+ cause. span( & tcx ) ,
314317 E0053 ,
315318 "method `{}` has an incompatible type for trait" ,
316319 trait_m. name) ;
@@ -346,10 +349,12 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
346349fn check_region_bounds_on_impl_method < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
347350 span : Span ,
348351 impl_m : & ty:: AssociatedItem ,
352+ trait_m : & ty:: AssociatedItem ,
349353 trait_generics : & ty:: Generics ,
350354 impl_generics : & ty:: Generics ,
351355 trait_to_skol_substs : & Substs < ' tcx > )
352356 -> Result < ( ) , ErrorReported > {
357+ let span = tcx. sess . codemap ( ) . def_span ( span) ;
353358 let trait_params = & trait_generics. regions [ ..] ;
354359 let impl_params = & impl_generics. regions [ ..] ;
355360
@@ -371,14 +376,18 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
371376 // are zero. Since I don't quite know how to phrase things at
372377 // the moment, give a kind of vague error message.
373378 if trait_params. len ( ) != impl_params. len ( ) {
374- struct_span_err ! ( tcx. sess,
375- span,
376- E0195 ,
377- "lifetime parameters or bounds on method `{}` do not match the \
378- trait declaration",
379- impl_m. name)
380- . span_label ( span, "lifetimes do not match trait" )
381- . emit ( ) ;
379+ let mut err = struct_span_err ! ( tcx. sess,
380+ span,
381+ E0195 ,
382+ "lifetime parameters or bounds on method `{}` do not match \
383+ the trait declaration",
384+ impl_m. name) ;
385+ err. span_label ( span, "lifetimes do not match method in trait" ) ;
386+ if let Some ( sp) = tcx. hir . span_if_local ( trait_m. def_id ) {
387+ err. span_label ( tcx. sess . codemap ( ) . def_span ( sp) ,
388+ "lifetimes in impl do not match this method in trait" ) ;
389+ }
390+ err. emit ( ) ;
382391 return Err ( ErrorReported ) ;
383392 }
384393
@@ -424,9 +433,9 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
424433 } ) . map ( |( ref impl_arg, ref trait_arg) | {
425434 ( impl_arg. span , Some ( trait_arg. span ) )
426435 } )
427- . unwrap_or_else ( || ( cause. span , tcx. hir . span_if_local ( trait_m. def_id ) ) )
436+ . unwrap_or_else ( || ( cause. span ( & tcx ) , tcx. hir . span_if_local ( trait_m. def_id ) ) )
428437 } else {
429- ( cause. span , tcx. hir . span_if_local ( trait_m. def_id ) )
438+ ( cause. span ( & tcx ) , tcx. hir . span_if_local ( trait_m. def_id ) )
430439 }
431440 }
432441 TypeError :: Sorts ( ExpectedFound { .. } ) => {
@@ -459,14 +468,14 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
459468 {
460469 ( impl_m_output. span ( ) , Some ( trait_m_output. span ( ) ) )
461470 } else {
462- ( cause. span , tcx. hir . span_if_local ( trait_m. def_id ) )
471+ ( cause. span ( & tcx ) , tcx. hir . span_if_local ( trait_m. def_id ) )
463472 }
464473 } )
465474 } else {
466- ( cause. span , tcx. hir . span_if_local ( trait_m. def_id ) )
475+ ( cause. span ( & tcx ) , tcx. hir . span_if_local ( trait_m. def_id ) )
467476 }
468477 }
469- _ => ( cause. span , tcx. hir . span_if_local ( trait_m. def_id ) ) ,
478+ _ => ( cause. span ( & tcx ) , tcx. hir . span_if_local ( trait_m. def_id ) ) ,
470479 }
471480}
472481
0 commit comments