diff options
| author | bors <bors@rust-lang.org> | 2021-05-06 17:42:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-06 17:42:32 +0000 |
| commit | 377d1a984cd2a53327092b90aa1d8b7e22d1e347 (patch) | |
| tree | 31123fc32dd8c0a30252d48d8e1b600aee63b426 /compiler/rustc_trait_selection/src/traits | |
| parent | d44f647ffcff0e1ff2c0f45b6a0ce9796d80f1ca (diff) | |
| parent | c1ef0f3050c3575d864740e14b4e49b36bb3dae1 (diff) | |
Auto merge of #84559 - jackh726:issue-84398, r=nikomatsakis
Deduplicate ParamCandidates with the same value except for bound vars Fixes #84398 This is kind of a hack. I wonder if we can get other types of candidates that are the same except for bound vars. This won't be a problem with Chalk, since we don't really need to know that there are two different "candidates" if they both give the same final substitution. r? `@nikomatsakis`
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e4aabbdb7ed..727285e4927 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1361,7 +1361,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) => false, (ParamCandidate(other), ParamCandidate(victim)) => { - if other.value == victim.value && victim.constness == Constness::NotConst { + let value_same_except_bound_vars = other.value.skip_binder() + == victim.value.skip_binder() + && !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 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 } else { |
