@@ -14,6 +14,8 @@ use rustc::ty;
1414use rustc:: traits:: { self , ProjectionMode } ;
1515use rustc:: ty:: error:: ExpectedFound ;
1616use rustc:: ty:: subst:: { self , Subst , Substs , VecPerParamSpace } ;
17+ use rustc:: hir:: map:: Node ;
18+ use rustc:: hir:: { ImplItemKind , TraitItem_ } ;
1719
1820use syntax:: ast;
1921use syntax_pos:: Span ;
@@ -461,7 +463,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
461463 // Compute skolemized form of impl and trait const tys.
462464 let impl_ty = impl_c. ty . subst ( tcx, impl_to_skol_substs) ;
463465 let trait_ty = trait_c. ty . subst ( tcx, & trait_to_skol_substs) ;
464- let origin = TypeOrigin :: Misc ( impl_c_span) ;
466+ let mut origin = TypeOrigin :: Misc ( impl_c_span) ;
465467
466468 let err = infcx. commit_if_ok ( |_| {
467469 // There is no "body" here, so just pass dummy id.
@@ -496,11 +498,31 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
496498 debug ! ( "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
497499 impl_ty,
498500 trait_ty) ;
501+
502+ // Locate the Span containing just the type of the offending impl
503+ if let Some ( impl_trait_node) = tcx. map . get_if_local ( impl_c. def_id ) {
504+ if let Node :: NodeImplItem ( impl_trait_item) = impl_trait_node {
505+ if let ImplItemKind :: Const ( ref ty, _) = impl_trait_item. node {
506+ origin = TypeOrigin :: Misc ( ty. span ) ;
507+ }
508+ }
509+ }
510+
499511 let mut diag = struct_span_err ! (
500512 tcx. sess, origin. span( ) , E0326 ,
501513 "implemented const `{}` has an incompatible type for trait" ,
502514 trait_c. name
503515 ) ;
516+
517+ // Add a label to the Span containing just the type of the item
518+ if let Some ( orig_trait_node) = tcx. map . get_if_local ( trait_c. def_id ) {
519+ if let Node :: NodeTraitItem ( orig_trait_item) = orig_trait_node {
520+ if let TraitItem_ :: ConstTraitItem ( ref ty, _) = orig_trait_item. node {
521+ diag. span_label ( ty. span , & format ! ( "original trait requirement" ) ) ;
522+ }
523+ }
524+ }
525+
504526 infcx. note_type_err (
505527 & mut diag, origin,
506528 Some ( infer:: ValuePairs :: Types ( ExpectedFound {
0 commit comments