Skip to content

Commit bc3516d

Browse files
reverse obligations for better diagnostics on multiple conflicting fn bounds
1 parent caa701e commit bc3516d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231231

232232
for obligation in traits::elaborate_obligations(
233233
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(),
235238
) {
236239
debug!(?obligation.predicate);
237240
let bound_predicate = obligation.predicate.kind();

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
670670
pub(in super::super) fn obligations_for_self_ty<'b>(
671671
&'b self,
672672
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+
{
674675
// FIXME: consider using `sub_root_var` here so we
675676
// can see through subtyping.
676677
let ty_var_root = self.root_var(self_ty);

0 commit comments

Comments
 (0)