Skip to content

Commit 835c6f7

Browse files
committed
Fix the order of the errors
1 parent 09a1bd5 commit 835c6f7

File tree

1 file changed

+15
-6
lines changed
  • compiler/rustc_trait_selection/src/error_reporting/traits

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
163163
// Ensure `T: Sized` and `T: WF` obligations come last. This lets us display diagnostics
164164
// with more relevant type information and hide redundant E0282 errors.
165165
errors.sort_by_key(|e| match e.obligation.predicate.kind().skip_binder() {
166-
ty::PredicateKind::Subtype(_) => {
167-
(-1, e.obligation.cause.span.len(), -(e.obligation.cause.span.index() as i32))
166+
ty::PredicateKind::Subtype(_)
167+
if e.obligation.cause.span.macro_backtrace().next().is_some_and(
168+
|trace| match trace.kind {
169+
ExpnKind::Macro(_, name) => {
170+
name.as_str().rsplit("::").next() == Some("format_args_nl")
171+
}
172+
_ => false,
173+
},
174+
) =>
175+
{
176+
(-1, e.obligation.cause.span.index())
168177
}
169178
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
170179
if self.tcx.is_lang_item(pred.def_id(), LangItem::Sized) =>
171180
{
172-
(1, 0, 0)
181+
(1, 0)
173182
}
174-
ty::PredicateKind::Coerce(_) => (2, 0, 0),
175-
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => (3, 0, 0),
176-
_ => (0, 0, 0),
183+
ty::PredicateKind::Coerce(_) => (2, 0),
184+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => (3, 0),
185+
_ => (0, 0),
177186
});
178187

179188
for (index, error) in errors.iter().enumerate() {

0 commit comments

Comments
 (0)