Skip to content

Commit a041ee2

Browse files
committed
Fix sorting logic for ErrorSortKey::SubtypeFormat
1 parent d0cdf80 commit a041ee2

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::*;
@@ -179,24 +179,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
179179
match e.obligation.predicate.kind().skip_binder() {
180180
ty::PredicateKind::Subtype(_)
181181
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) =>
189185
{
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))
200190
}
201191
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
202192
if self.tcx.is_lang_item(pred.def_id(), LangItem::Sized) =>
@@ -288,6 +278,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
288278
reported.unwrap_or_else(|| self.dcx().delayed_bug("failed to report fulfillment errors"))
289279
}
290280

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

0 commit comments

Comments
 (0)