@@ -22,7 +22,7 @@ use rustc_infer::traits::{
22
22
} ;
23
23
use rustc_middle:: ty:: print:: { PrintTraitRefExt as _, with_no_trimmed_paths} ;
24
24
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
25
- use rustc_span:: { ErrorGuaranteed , ExpnKind , Span } ;
25
+ use rustc_span:: { ErrorGuaranteed , ExpnKind , Span , sym } ;
26
26
use tracing:: { info, instrument} ;
27
27
28
28
pub use self :: overflow:: * ;
@@ -179,24 +179,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
179
179
match e. obligation . predicate . kind ( ) . skip_binder ( ) {
180
180
ty:: PredicateKind :: Subtype ( _)
181
181
if let Some ( def_id) = outer_expn_data. macro_def_id
182
- && ( self
183
- . tcx
184
- . is_diagnostic_item ( rustc_span:: sym:: format_args_nl_macro, def_id)
185
- || self . tcx . is_diagnostic_item (
186
- rustc_span:: sym:: format_args_macro,
187
- def_id,
188
- ) ) =>
182
+ && ( self . tcx . is_diagnostic_item ( sym:: format_args_nl_macro, def_id)
183
+ || self . tcx . is_diagnostic_item ( sym:: format_args_macro, def_id) )
184
+ && self . is_source_span ( span) =>
189
185
{
190
- let sm = self . tcx . sess . source_map ( ) ;
191
- let lc = sm. span_to_location_info ( span) ;
192
-
193
- if sm. span_to_embeddable_string ( span)
194
- == sm. span_to_embeddable_string ( outer_expn_data. call_site )
195
- {
196
- ErrorSortKey :: OtherKind
197
- } else {
198
- ErrorSortKey :: SubtypeFormat ( Reverse ( lc. 2 ) )
199
- }
186
+ let source_map = self . tcx . sess . source_map ( ) ;
187
+ let ( _, _, lo_col, _, _) = source_map. span_to_location_info ( span) ;
188
+
189
+ ErrorSortKey :: SubtypeFormat ( Reverse ( lo_col) )
200
190
}
201
191
ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( pred) )
202
192
if self . tcx . is_lang_item ( pred. def_id ( ) , LangItem :: Sized ) =>
@@ -288,6 +278,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
288
278
reported. unwrap_or_else ( || self . dcx ( ) . delayed_bug ( "failed to report fulfillment errors" ) )
289
279
}
290
280
281
+ fn is_source_span ( & self , span : Span ) -> bool {
282
+ let source_map = self . tcx . sess . source_map ( ) ;
283
+
284
+ let outer_expn_data = span. ctxt ( ) . outer_expn_data ( ) ;
285
+ let outer_callsite = outer_expn_data. call_site . source_callsite ( ) ;
286
+
287
+ let span_info = source_map. span_to_location_info ( span) ;
288
+ let outer_info = source_map. span_to_location_info ( outer_callsite) ;
289
+
290
+ match ( span_info, outer_info) {
291
+ ( ( Some ( sf1) , _, _, _, _) , ( Some ( sf2) , _, _, _, _) ) => sf1. src_hash == sf2. src_hash ,
292
+ _ => false ,
293
+ }
294
+ }
295
+
291
296
#[ instrument( skip( self ) , level = "debug" ) ]
292
297
fn report_fulfillment_error ( & self , error : & FulfillmentError < ' tcx > ) -> ErrorGuaranteed {
293
298
let mut error = FulfillmentError {
0 commit comments