about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJack Huey <31162821+jackh726@users.noreply.github.com>2021-05-06 10:19:51 -0400
committerGitHub <noreply@github.com>2021-05-06 10:19:51 -0400
commitc1ef0f3050c3575d864740e14b4e49b36bb3dae1 (patch)
tree38557dd20081b6bfdaa1b1984034963a5d5f7db6
parent9f0693969a0ac0a0193c7c367e3292b5315b2747 (diff)
downloadrust-c1ef0f3050c3575d864740e14b4e49b36bb3dae1.tar.gz
rust-c1ef0f3050c3575d864740e14b4e49b36bb3dae1.zip
Pick candidate with fewer bound vars
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index c9ba8e6dc8c..727285e4927 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -1366,11 +1366,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                     && !other.value.skip_binder().has_escaping_bound_vars();
                 if value_same_except_bound_vars {
                     // See issue #84398. In short, we can generate multiple ParamCandidates which are
-                    // the same except for unused bound vars. Just pick the current one (the should
-                    // both evaluate to the same answer). This is probably best characterized as a
-                    // "hack", since we might prefer to just do our best to *not* create essentially
-                    // duplicate candidates in the first place.
-                    true
+                    // the same except for unused bound vars. Just pick the one with the fewest bound vars
+                    // or the current one if tied (they should both evaluate to the same answer). This is
+                    // probably best characterized as a "hack", since we might prefer to just do our
+                    // best to *not* create essentially duplicate candidates in the first place.
+                    other.value.bound_vars().len() <= victim.value.bound_vars().len()
                 } else if other.value == victim.value && victim.constness == Constness::NotConst {
                     // Drop otherwise equivalent non-const candidates in favor of const candidates.
                     true