@@ -36,7 +36,7 @@ use rustc_middle::ty::{
3636 TypeSuperFoldable , TypeVisitable , TypeckResults ,
3737} ;
3838use rustc_span:: symbol:: { sym, Ident , Symbol } ;
39- use rustc_span:: { BytePos , DesugaringKind , ExpnKind , Span , DUMMY_SP } ;
39+ use rustc_span:: { BytePos , DesugaringKind , ExpnKind , MacroKind , Span , DUMMY_SP } ;
4040use rustc_target:: spec:: abi;
4141use std:: ops:: Deref ;
4242
@@ -2949,7 +2949,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29492949 // FIXME: we should do something else so that it works even on crate foreign
29502950 // auto traits.
29512951 is_auto_trait = matches ! ( is_auto, hir:: IsAuto :: Yes ) ;
2952- err. span_note ( ident. span , & msg)
2952+ err. span_note ( ident. span , & msg) ;
29532953 }
29542954 Some ( Node :: Item ( hir:: Item {
29552955 kind : hir:: ItemKind :: Impl ( hir:: Impl { of_trait, self_ty, .. } ) ,
@@ -2960,9 +2960,29 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29602960 spans. push ( trait_ref. path . span ) ;
29612961 }
29622962 spans. push ( self_ty. span ) ;
2963- err. span_note ( spans, & msg)
2963+ let mut spans: MultiSpan = spans. into ( ) ;
2964+ if matches ! (
2965+ self_ty. span. ctxt( ) . outer_expn_data( ) . kind,
2966+ ExpnKind :: Macro ( MacroKind :: Derive , _)
2967+ ) || matches ! (
2968+ of_trait. as_ref( ) . map( |t| t. path. span. ctxt( ) . outer_expn_data( ) . kind) ,
2969+ Some ( ExpnKind :: Macro ( MacroKind :: Derive , _) )
2970+ ) {
2971+ spans. push_span_label (
2972+ data. span ,
2973+ "unsatisfied trait bound introduced in this `derive` macro" ,
2974+ ) ;
2975+ } else if !data. span . is_dummy ( ) && !data. span . overlaps ( self_ty. span ) {
2976+ spans. push_span_label (
2977+ data. span ,
2978+ "unsatisfied trait bound introduced here" ,
2979+ ) ;
2980+ }
2981+ err. span_note ( spans, & msg) ;
2982+ }
2983+ _ => {
2984+ err. note ( & msg) ;
29642985 }
2965- _ => err. note ( & msg) ,
29662986 } ;
29672987
29682988 if let Some ( file) = file {
0 commit comments