@@ -36,7 +36,7 @@ use rustc_middle::ty::{
36
36
TypeSuperFoldable , TypeVisitable , TypeckResults ,
37
37
} ;
38
38
use 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 } ;
40
40
use rustc_target:: spec:: abi;
41
41
use std:: ops:: Deref ;
42
42
@@ -2949,7 +2949,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2949
2949
// FIXME: we should do something else so that it works even on crate foreign
2950
2950
// auto traits.
2951
2951
is_auto_trait = matches ! ( is_auto, hir:: IsAuto :: Yes ) ;
2952
- err. span_note ( ident. span , & msg)
2952
+ err. span_note ( ident. span , & msg) ;
2953
2953
}
2954
2954
Some ( Node :: Item ( hir:: Item {
2955
2955
kind : hir:: ItemKind :: Impl ( hir:: Impl { of_trait, self_ty, .. } ) ,
@@ -2960,9 +2960,29 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2960
2960
spans. push ( trait_ref. path . span ) ;
2961
2961
}
2962
2962
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) ;
2964
2985
}
2965
- _ => err. note ( & msg) ,
2966
2986
} ;
2967
2987
2968
2988
if let Some ( file) = file {
0 commit comments