diff options
| author | Michael Goulet <michael@errs.io> | 2022-10-15 18:48:13 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-11-03 15:52:39 +0000 |
| commit | bc3516d474a6ab5e5116a2ec32f5d236d479cab3 (patch) | |
| tree | 815960ef4cdba67486cdda33da2503dcdad46ac1 | |
| parent | caa701e3c190c4d77634c9075548746e4917e56d (diff) | |
| download | rust-bc3516d474a6ab5e5116a2ec32f5d236d479cab3.tar.gz rust-bc3516d474a6ab5e5116a2ec32f5d236d479cab3.zip | |
reverse obligations for better diagnostics on multiple conflicting fn bounds
| -rw-r--r-- | compiler/rustc_hir_typeck/src/closure.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 3 |
2 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 4f8ac45d5a6..14f6e7d36be 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -231,7 +231,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for obligation in traits::elaborate_obligations( self.tcx, - self.obligations_for_self_ty(expected_vid).collect(), + // Reverse the obligations here, since `elaborate_*` uses a stack, + // and we want to keep inference generally in the same order of + // the registered obligations. + self.obligations_for_self_ty(expected_vid).rev().collect(), ) { debug!(?obligation.predicate); let bound_predicate = obligation.predicate.kind(); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index d2962a3836f..7c22eaf18f8 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -670,7 +670,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn obligations_for_self_ty<'b>( &'b self, self_ty: ty::TyVid, - ) -> impl Iterator<Item = traits::PredicateObligation<'tcx>> + Captures<'tcx> + 'b { + ) -> impl DoubleEndedIterator<Item = traits::PredicateObligation<'tcx>> + Captures<'tcx> + 'b + { // FIXME: consider using `sub_root_var` here so we // can see through subtyping. let ty_var_root = self.root_var(self_ty); |
