Skip to content

Commit a9bc2ef

Browse files
Rollup merge of #88851 - fee1-dead:dup-bound, r=oli-obk
Fix duplicate bounds for const_trait_impl Fixes #88383. Compare the constness of the candidates before winnowing and removing a `~const` `BoundCandidate`.
2 parents 5eb7783 + a0b83f5 commit a9bc2ef

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1487,10 +1487,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14871487
) => false,
14881488

14891489
(ParamCandidate(other), ParamCandidate(victim)) => {
1490-
let value_same_except_bound_vars = other.value.skip_binder()
1490+
let same_except_bound_vars = other.value.skip_binder()
14911491
== victim.value.skip_binder()
1492+
&& other.constness == victim.constness
14921493
&& !other.value.skip_binder().has_escaping_bound_vars();
1493-
if value_same_except_bound_vars {
1494+
if same_except_bound_vars {
14941495
// See issue #84398. In short, we can generate multiple ParamCandidates which are
14951496
// the same except for unused bound vars. Just pick the one with the fewest bound vars
14961497
// or the current one if tied (they should both evaluate to the same answer). This is

src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ impl const PartialEq for S {
1616

1717
// This duplicate bound should not result in ambiguities. It should be equivalent to a single ~const
1818
// bound.
19-
// const fn equals_self<T: PartialEq + ~const PartialEq>(t: &T) -> bool {
20-
// FIXME(fee1-dead)^ why should the order matter here?
21-
const fn equals_self<T: ~const PartialEq + PartialEq>(t: &T) -> bool {
19+
const fn equals_self<T: PartialEq + ~const PartialEq>(t: &T) -> bool {
2220
*t == *t
2321
}
2422

25-
pub const EQ: bool = equals_self(&S);
23+
trait A: PartialEq {}
24+
impl<T: PartialEq> A for T {}
25+
26+
const fn equals_self2<T: A + ~const PartialEq>(t: &T) -> bool {
27+
*t == *t
28+
}
29+
30+
pub const EQ: bool = equals_self(&S) && equals_self2(&S);
2631

2732
fn main() {}

0 commit comments

Comments
 (0)