@@ -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:: * ;
@@ -189,24 +189,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
189
189
match e. obligation . predicate . kind ( ) . skip_binder ( ) {
190
190
ty:: PredicateKind :: Subtype ( _)
191
191
if let Some ( def_id) = outer_expn_data. macro_def_id
192
- && ( self
193
- . tcx
194
- . is_diagnostic_item ( rustc_span:: sym:: format_args_nl_macro, def_id)
195
- || self . tcx . is_diagnostic_item (
196
- rustc_span:: sym:: format_args_macro,
197
- def_id,
198
- ) ) =>
192
+ && ( self . tcx . is_diagnostic_item ( sym:: format_args_nl_macro, def_id)
193
+ || self . tcx . is_diagnostic_item ( sym:: format_args_macro, def_id) )
194
+ && self . is_source_span ( span) =>
199
195
{
200
- let sm = self . tcx . sess . source_map ( ) ;
201
- let lc = sm. span_to_location_info ( span) ;
202
-
203
- if sm. span_to_embeddable_string ( span)
204
- == sm. span_to_embeddable_string ( outer_expn_data. call_site )
205
- {
206
- ErrorSortKey :: OtherKind
207
- } else {
208
- ErrorSortKey :: SubtypeFormat ( Reverse ( lc. 2 ) )
209
- }
196
+ let source_map = self . tcx . sess . source_map ( ) ;
197
+ let ( _, _, lo_col, _, _) = source_map. span_to_location_info ( span) ;
198
+
199
+ ErrorSortKey :: SubtypeFormat ( Reverse ( lo_col) )
210
200
}
211
201
_ if maybe_sizedness_did == self . tcx . lang_items ( ) . sized_trait ( ) => ErrorSortKey :: SizedTrait ,
212
202
_ if maybe_sizedness_did == self . tcx . lang_items ( ) . meta_sized_trait ( ) => ErrorSortKey :: MetaSizedTrait ,
@@ -296,6 +286,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
296
286
reported. unwrap_or_else ( || self . dcx ( ) . delayed_bug ( "failed to report fulfillment errors" ) )
297
287
}
298
288
289
+ fn is_source_span ( & self , span : Span ) -> bool {
290
+ let source_map = self . tcx . sess . source_map ( ) ;
291
+
292
+ let outer_expn_data = span. ctxt ( ) . outer_expn_data ( ) ;
293
+ let outer_callsite = outer_expn_data. call_site . source_callsite ( ) ;
294
+
295
+ let span_info = source_map. span_to_location_info ( span) ;
296
+ let outer_info = source_map. span_to_location_info ( outer_callsite) ;
297
+
298
+ match ( span_info, outer_info) {
299
+ ( ( Some ( sf1) , _, _, _, _) , ( Some ( sf2) , _, _, _, _) ) => sf1. src_hash == sf2. src_hash ,
300
+ _ => false ,
301
+ }
302
+ }
303
+
299
304
#[ instrument( skip( self ) , level = "debug" ) ]
300
305
fn report_fulfillment_error ( & self , error : & FulfillmentError < ' tcx > ) -> ErrorGuaranteed {
301
306
let mut error = FulfillmentError {
0 commit comments