Skip to content

Commit 09a1bd5

Browse files
committed
Adjust the order of the errors
1 parent 7b84c9e commit 09a1bd5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

compiler/rustc_span/src/span_encoding.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ impl Span {
281281
}
282282
}
283283

284+
#[inline]
285+
pub fn len(self) -> u32 {
286+
(self.len_with_tag_or_marker & !PARENT_TAG) as u32
287+
}
288+
289+
#[inline]
290+
pub fn index(self) -> u32 {
291+
self.lo_or_index
292+
}
293+
284294
#[inline]
285295
pub fn data(self) -> SpanData {
286296
let data = self.data_untracked();

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,17 @@ 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))
168+
}
166169
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
167170
if self.tcx.is_lang_item(pred.def_id(), LangItem::Sized) =>
168171
{
169-
1
172+
(1, 0, 0)
170173
}
171-
ty::PredicateKind::Coerce(_) => 2,
172-
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => 3,
173-
_ => 0,
174+
ty::PredicateKind::Coerce(_) => (2, 0, 0),
175+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => (3, 0, 0),
176+
_ => (0, 0, 0),
174177
});
175178

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

0 commit comments

Comments
 (0)