diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2021-09-11 09:40:19 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2021-09-11 09:40:19 +0000 |
| commit | a0b83f542f91699838c65d772b0eb6aeb276fb67 (patch) | |
| tree | 7c79ca264fd6abaa98854268c3f9cb4f3822009b | |
| parent | 497ee321af3b8496eaccd7af7b437f18bab81abf (diff) | |
| download | rust-a0b83f542f91699838c65d772b0eb6aeb276fb67.tar.gz rust-a0b83f542f91699838c65d772b0eb6aeb276fb67.zip | |
Fix duplicate bounds for const_trait_impl
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs | 13 |
2 files changed, 12 insertions, 6 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 22013fb79cf..3c83938ce43 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -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 diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs index 7185376b440..cc24dbd96d2 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs @@ -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() {} |
