Skip to content

Commit fb327ab

Browse files
jackh726Mark-Simulacrum
authored andcommitted
Deduplicate ParamCandidates with the same value except for bound vars
1 parent e58c811 commit fb327ab

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13611361
) => false,
13621362

13631363
(ParamCandidate(other), ParamCandidate(victim)) => {
1364-
if other.value == victim.value && victim.constness == Constness::NotConst {
1364+
let value_same_except_bound_vars = other.value.skip_binder()
1365+
== victim.value.skip_binder()
1366+
&& !other.value.skip_binder().has_escaping_bound_vars();
1367+
if value_same_except_bound_vars {
1368+
// See issue #84398. In short, we can generate multiple ParamCandidates which are
1369+
// the same except for unused bound vars. Just pick the current one (the should
1370+
// both evaluate to the same answer). This is probably best characterized as a
1371+
// "hack", since we might prefer to just do our best to *not* create essentially
1372+
// duplicate candidates in the first place.
1373+
true
1374+
} else if other.value == victim.value && victim.constness == Constness::NotConst {
13651375
// Drop otherwise equivalent non-const candidates in favor of const candidates.
13661376
true
13671377
} else {

src/test/ui/lifetimes/issue-84398.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
pub trait Deserialize<'de>: Sized {}
4+
pub trait DeserializeOwned: for<'de> Deserialize<'de> {}
5+
6+
pub trait Extensible {
7+
type Config;
8+
}
9+
10+
// The `C` here generates a `C: Sized` candidate
11+
pub trait Installer<C> {
12+
fn init<B: Extensible<Config = C>>(&mut self) -> ()
13+
where
14+
// This clause generates a `for<'de> C: Sized` candidate
15+
B::Config: DeserializeOwned,
16+
{
17+
}
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)