Skip to content

Commit 3265525

Browse files
committed
Fix sorting logic for ErrorSortKey::SubtypeFormat
1 parent 1a5236f commit 3265525

File tree

1 file changed

+23
-18
lines changed
  • compiler/rustc_trait_selection/src/error_reporting/traits

1 file changed

+23
-18
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_infer::traits::{
2222
};
2323
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
2424
use rustc_middle::ty::{self, Ty, TyCtxt};
25-
use rustc_span::{ErrorGuaranteed, ExpnKind, Span};
25+
use rustc_span::{ErrorGuaranteed, ExpnKind, Span, sym};
2626
use tracing::{info, instrument};
2727

2828
pub use self::overflow::*;
@@ -189,24 +189,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
189189
match e.obligation.predicate.kind().skip_binder() {
190190
ty::PredicateKind::Subtype(_)
191191
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) =>
199195
{
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))
210200
}
211201
_ if maybe_sizedness_did == self.tcx.lang_items().sized_trait() => ErrorSortKey::SizedTrait,
212202
_ if maybe_sizedness_did == self.tcx.lang_items().meta_sized_trait() => ErrorSortKey::MetaSizedTrait,
@@ -296,6 +286,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
296286
reported.unwrap_or_else(|| self.dcx().delayed_bug("failed to report fulfillment errors"))
297287
}
298288

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+
299304
#[instrument(skip(self), level = "debug")]
300305
fn report_fulfillment_error(&self, error: &FulfillmentError<'tcx>) -> ErrorGuaranteed {
301306
let mut error = FulfillmentError {

0 commit comments

Comments
 (0)