Skip to content

Commit e6238ba

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 1229c82 commit e6238ba

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
@@ -160,17 +160,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
160160
})
161161
.collect();
162162

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

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

0 commit comments

Comments
 (0)