Skip to content

Commit db6a443

Browse files
authored
Merge pull request #503 from YuhanLiin/indexmap-partialeq
Relax indexmap PartialEq bounds so value doesn't need to be Eq
2 parents 877db42 + 1052f4d commit db6a443

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
5858
- Changed `stable_deref_trait` to a platform-dependent dependency.
5959
- Changed `SortedLinkedList::pop` return type from `Result<T, ()>` to `Option<T>` to match `std::vec::pop`.
6060
- `Vec::capacity` is no longer a `const` function.
61+
- Relaxed bounds on `PartialEq` for `IndexMap` from `V: Eq` to `V1: PartialEq<V2>`.
62+
- Relaxed bounds on `PartialEq` for `LinearMap` from `V: PartialEq` to `V1: PartialEq<V2>`.
6163

6264
### Fixed
6365

src/indexmap.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,15 +1276,15 @@ where
12761276
}
12771277
}
12781278

1279-
impl<K, V, S, S2, const N: usize, const N2: usize> PartialEq<IndexMap<K, V, S2, N2>>
1280-
for IndexMap<K, V, S, N>
1279+
impl<K, V1, V2, S1, S2, const N1: usize, const N2: usize> PartialEq<IndexMap<K, V2, S2, N2>>
1280+
for IndexMap<K, V1, S1, N1>
12811281
where
12821282
K: Eq + Hash,
1283-
V: Eq,
1284-
S: BuildHasher,
1283+
V1: PartialEq<V2>,
1284+
S1: BuildHasher,
12851285
S2: BuildHasher,
12861286
{
1287-
fn eq(&self, other: &IndexMap<K, V, S2, N2>) -> bool {
1287+
fn eq(&self, other: &IndexMap<K, V2, S2, N2>) -> bool {
12881288
self.len() == other.len()
12891289
&& self
12901290
.iter()
@@ -1879,4 +1879,11 @@ mod tests {
18791879
assert_eq!(value, i + 1);
18801880
}
18811881
}
1882+
1883+
#[test]
1884+
fn partial_eq_floats() {
1885+
// Make sure `PartialEq` is implemented even if `V` doesn't implement `Eq`.
1886+
let map: FnvIndexMap<usize, f32, 4> = Default::default();
1887+
assert_eq!(map, map);
1888+
}
18821889
}

src/linear_map.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,13 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
614614
}
615615
}
616616

617-
impl<K, V, S1: LinearMapStorage<K, V> + ?Sized, S2: LinearMapStorage<K, V> + ?Sized>
618-
PartialEq<LinearMapInner<K, V, S2>> for LinearMapInner<K, V, S1>
617+
impl<K, V1, V2, S1: LinearMapStorage<K, V1> + ?Sized, S2: LinearMapStorage<K, V2> + ?Sized>
618+
PartialEq<LinearMapInner<K, V2, S2>> for LinearMapInner<K, V1, S1>
619619
where
620620
K: Eq,
621-
V: PartialEq,
621+
V1: PartialEq<V2>,
622622
{
623-
fn eq(&self, other: &LinearMapInner<K, V, S2>) -> bool {
623+
fn eq(&self, other: &LinearMapInner<K, V2, S2>) -> bool {
624624
self.len() == other.len()
625625
&& self
626626
.iter()
@@ -745,4 +745,11 @@ mod test {
745745
) -> &'c LinearMapView<&'b (), u32> {
746746
x
747747
}
748+
749+
#[test]
750+
fn partial_eq_floats() {
751+
// Make sure `PartialEq` is implemented even if `V` doesn't implement `Eq`.
752+
let map: LinearMap<usize, f32, 4> = Default::default();
753+
assert_eq!(map, map);
754+
}
748755
}

0 commit comments

Comments
 (0)