reverse obligations for better diagnostics on multiple conflicting fn… · rust-lang/rust@bc3516d (original) (raw)

File tree

2 files changed

lines changed

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -231,7 +231,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231 231
232 232 for obligation in traits::elaborate_obligations(
233 233 self.tcx,
234 -self.obligations_for_self_ty(expected_vid).collect(),
234 +// Reverse the obligations here, since `elaborate_*` uses a stack,
235 +// and we want to keep inference generally in the same order of
236 +// the registered obligations.
237 +self.obligations_for_self_ty(expected_vid).rev().collect(),
235 238 ) {
236 239 debug!(?obligation.predicate);
237 240 let bound_predicate = obligation.predicate.kind();
Original file line number Diff line number Diff line change
@@ -670,7 +670,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
670 670 pub(in super::super) fn obligations_for_self_ty<'b>(
671 671 &'b self,
672 672 self_ty: ty::TyVid,
673 -) -> impl Iterator<Item = traits::PredicateObligation<'tcx>> + Captures<'tcx> + 'b {
673 +) -> impl DoubleEndedIterator<Item = traits::PredicateObligation<'tcx>> + Captures<'tcx> + 'b
674 +{
674 675 // FIXME: consider using `sub_root_var` here so we
675 676 // can see through subtyping.
676 677 let ty_var_root = self.root_var(self_ty);