Skip to content

Commit

Permalink
Rollup merge of rust-lang#88851 - fee1-dead:dup-bound, r=oli-obk
Browse files Browse the repository at this point in the history
Fix duplicate bounds for const_trait_impl

Fixes rust-lang#88383.

Compare the constness of the candidates before winnowing and removing a `~const` `BoundCandidate`.
  • Loading branch information
GuillaumeGomez authored Sep 13, 2021
2 parents 5eb7783 + a0b83f5 commit a9bc2ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,10 +1487,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) => false,

(ParamCandidate(other), ParamCandidate(victim)) => {
let value_same_except_bound_vars = other.value.skip_binder()
let same_except_bound_vars = other.value.skip_binder()
== victim.value.skip_binder()
&& other.constness == victim.constness
&& !other.value.skip_binder().has_escaping_bound_vars();
if value_same_except_bound_vars {
if 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ impl const PartialEq for S {

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

pub const EQ: bool = equals_self(&S);
trait A: PartialEq {}
impl<T: PartialEq> A for T {}

const fn equals_self2<T: A + ~const PartialEq>(t: &T) -> bool {
*t == *t
}

pub const EQ: bool = equals_self(&S) && equals_self2(&S);

fn main() {}

0 comments on commit a9bc2ef

Please sign in to comment.