Skip to content

Commit e56c8f5

Browse files
committed
trait_sel: sort {Meta,Pointee}Sized diagnostics last
Like `Sized` diagnostics, sorting `MetaSized` and `PointeeSized` diagnostics last prevents earlier more useful diagnostics from being skipped because there has already been error tainting.
1 parent 81c2385 commit e56c8f5

File tree

1 file changed

+17
-10
lines changed
  • compiler/rustc_trait_selection/src/error_reporting/traits

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
164164
})
165165
.collect();
166166

167-
// Ensure `T: Sized` and `T: WF` obligations come last. This lets us display diagnostics
168-
// with more relevant type information and hide redundant E0282 errors.
169-
errors.sort_by_key(|e| match e.obligation.predicate.kind().skip_binder() {
170-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred))
171-
if self.tcx.is_lang_item(pred.def_id(), LangItem::Sized) =>
172-
{
173-
1
167+
// Ensure `T: Sized`, `T: MetaSized`, `T: PointeeSized` and `T: WF` obligations come last.
168+
// This lets us display diagnostics with more relevant type information and hide redundant
169+
// E0282 errors.
170+
errors.sort_by_key(|e| {
171+
let maybe_sizedness_did = match e.obligation.predicate.kind().skip_binder() {
172+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => Some(pred.def_id()),
173+
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(pred)) => Some(pred.def_id()),
174+
_ => None,
175+
};
176+
177+
match e.obligation.predicate.kind().skip_binder() {
178+
_ if maybe_sizedness_did == self.tcx.lang_items().sized_trait() => 1,
179+
_ if maybe_sizedness_did == self.tcx.lang_items().metasized_trait() => 2,
180+
_ if maybe_sizedness_did == self.tcx.lang_items().pointeesized_trait() => 3,
181+
ty::PredicateKind::Coerce(_) => 4,
182+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => 5,
183+
_ => 0,
174184
}
175-
ty::PredicateKind::Coerce(_) => 2,
176-
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => 3,
177-
_ => 0,
178185
});
179186

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

0 commit comments

Comments
 (0)