@@ -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 ;
@@ -461,7 +463,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
461
463
// Compute skolemized form of impl and trait const tys.
462
464
let impl_ty = impl_c. ty . subst ( tcx, impl_to_skol_substs) ;
463
465
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) ;
465
467
466
468
let err = infcx. commit_if_ok ( |_| {
467
469
// 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>,
496
498
debug ! ( "checking associated const for compatibility: impl ty {:?}, trait ty {:?}" ,
497
499
impl_ty,
498
500
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
+
499
511
let mut diag = struct_span_err ! (
500
512
tcx. sess, origin. span( ) , E0326 ,
501
513
"implemented const `{}` has an incompatible type for trait" ,
502
514
trait_c. name
503
515
) ;
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
+
504
526
infcx. note_type_err (
505
527
& mut diag, origin,
506
528
Some ( infer:: ValuePairs :: Types ( ExpectedFound {
0 commit comments