@@ -14,6 +14,8 @@ use rustc::ty;
14
14
use rustc:: traits:: { self , ProjectionMode } ;
15
15
use rustc:: ty:: error:: ExpectedFound ;
16
16
use rustc:: ty:: subst:: { self , Subst , Substs , VecPerParamSpace } ;
17
+ use rustc:: hir:: map:: Node ;
18
+ use rustc:: hir:: { ImplItemKind , TraitItem_ } ;
17
19
18
20
use syntax:: ast;
19
21
use syntax_pos:: Span ;
@@ -447,7 +449,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
447
449
// Compute skolemized form of impl and trait const tys.
448
450
let impl_ty = impl_c. ty . subst ( tcx, impl_to_skol_substs) ;
449
451
let trait_ty = trait_c. ty . subst ( tcx, & trait_to_skol_substs) ;
450
- let origin = TypeOrigin :: Misc ( impl_c_span) ;
452
+ let mut origin = TypeOrigin :: Misc ( impl_c_span) ;
451
453
452
454
let err = infcx. commit_if_ok ( |_| {
453
455
// There is no "body" here, so just pass dummy id.
@@ -482,11 +484,31 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
482
484
debug ! ( "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
483
485
impl_ty,
484
486
trait_ty) ;
487
+
488
+ // Locate the Span containing just the type of the offending impl
489
+ if let Some ( impl_trait_node) = tcx. map . get_if_local ( impl_c. def_id ) {
490
+ if let Node :: NodeImplItem ( impl_trait_item) = impl_trait_node {
491
+ if let ImplItemKind :: Const ( ref ty, _) = impl_trait_item. node {
492
+ origin = TypeOrigin :: Misc ( ty. span ) ;
493
+ }
494
+ }
495
+ }
496
+
485
497
let mut diag = struct_span_err ! (
486
498
tcx. sess, origin. span( ) , E0326 ,
487
499
"implemented const `{}` has an incompatible type for trait" ,
488
500
trait_c. name
489
501
) ;
502
+
503
+ // Add a label to the Span containing just the type of the item
504
+ if let Some ( orig_trait_node) = tcx. map . get_if_local ( trait_c. def_id ) {
505
+ if let Node :: NodeTraitItem ( orig_trait_item) = orig_trait_node {
506
+ if let TraitItem_ :: ConstTraitItem ( ref ty, _) = orig_trait_item. node {
507
+ diag. span_label ( ty. span , & format ! ( "original trait requirement" ) ) ;
508
+ }
509
+ }
510
+ }
511
+
490
512
infcx. note_type_err (
491
513
& mut diag, origin,
492
514
Some ( infer:: ValuePairs :: Types ( ExpectedFound {
0 commit comments