@@ -40,6 +40,8 @@ pub fn compare_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
40
40
debug ! ( "compare_impl_method(impl_trait_ref={:?})" ,
41
41
impl_trait_ref) ;
42
42
43
+ let impl_m_span = tcx. sess . codemap ( ) . def_span ( impl_m_span) ;
44
+
43
45
if let Err ( ErrorReported ) = compare_self_type ( tcx,
44
46
impl_m,
45
47
impl_m_span,
@@ -186,6 +188,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
186
188
check_region_bounds_on_impl_method ( tcx,
187
189
impl_m_span,
188
190
impl_m,
191
+ trait_m,
189
192
& trait_m_generics,
190
193
& impl_m_generics,
191
194
trait_to_skol_substs) ?;
@@ -310,7 +313,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
310
313
} ;
311
314
312
315
let mut diag = struct_span_err ! ( tcx. sess,
313
- cause. span,
316
+ cause. span( & tcx ) ,
314
317
E0053 ,
315
318
"method `{}` has an incompatible type for trait" ,
316
319
trait_m. name) ;
@@ -346,10 +349,12 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
346
349
fn check_region_bounds_on_impl_method < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
347
350
span : Span ,
348
351
impl_m : & ty:: AssociatedItem ,
352
+ trait_m : & ty:: AssociatedItem ,
349
353
trait_generics : & ty:: Generics ,
350
354
impl_generics : & ty:: Generics ,
351
355
trait_to_skol_substs : & Substs < ' tcx > )
352
356
-> Result < ( ) , ErrorReported > {
357
+ let span = tcx. sess . codemap ( ) . def_span ( span) ;
353
358
let trait_params = & trait_generics. regions [ ..] ;
354
359
let impl_params = & impl_generics. regions [ ..] ;
355
360
@@ -371,14 +376,18 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
371
376
// are zero. Since I don't quite know how to phrase things at
372
377
// the moment, give a kind of vague error message.
373
378
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 ( ) ;
382
391
return Err ( ErrorReported ) ;
383
392
}
384
393
@@ -424,9 +433,9 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
424
433
} ) . map ( |( ref impl_arg, ref trait_arg) | {
425
434
( impl_arg. span , Some ( trait_arg. span ) )
426
435
} )
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 ) ) )
428
437
} 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 ) )
430
439
}
431
440
}
432
441
TypeError :: Sorts ( ExpectedFound { .. } ) => {
@@ -459,14 +468,14 @@ fn extract_spans_for_error_reporting<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a
459
468
{
460
469
( impl_m_output. span ( ) , Some ( trait_m_output. span ( ) ) )
461
470
} 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 ) )
463
472
}
464
473
} )
465
474
} 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 ) )
467
476
}
468
477
}
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 ) ) ,
470
479
}
471
480
}
472
481
0 commit comments