Skip to content

Commit 5be552d

Browse files
committed
Implement additional suggestions from review
1 parent 4e1d8ce commit 5be552d

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ impl std::error::Error for TryReserveError {}
275275
///
276276
/// It indicates one of two possible errors:
277277
/// - An index is out-of-bounds.
278-
/// - The same index appeared multiple times in the array
279-
/// (or different but overlapping indices when ranges are provided).
278+
/// - The same index appeared multiple times in the array.
279+
// (or different but overlapping indices when ranges are provided)
280280
#[derive(Debug, Clone, PartialEq, Eq)]
281281
pub enum GetDisjointMutError {
282282
/// An index provided was out-of-bounds for the slice.

src/map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,9 @@ where
798798
/// let mut map = indexmap::IndexMap::from([(1, 'a'), (3, 'b'), (2, 'c')]);
799799
/// assert_eq!(map.get_disjoint_mut([&2, &1]), [Some(&mut 'c'), Some(&mut 'a')]);
800800
/// ```
801-
#[allow(unsafe_code)]
802801
pub fn get_disjoint_mut<Q, const N: usize>(&mut self, keys: [&Q; N]) -> [Option<&mut V>; N]
803802
where
804-
Q: Hash + Equivalent<K> + ?Sized,
803+
Q: ?Sized + Hash + Equivalent<K>,
805804
{
806805
let indices = keys.map(|key| self.get_index_of(key));
807806
match self.as_mut_slice().get_disjoint_opt_mut(indices) {

src/map/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl<K, V> Slice<K, V> {
297297
};
298298
if idx >= len {
299299
return Err(GetDisjointMutError::IndexOutOfBounds);
300-
} else if indices[i + 1..N].contains(&Some(idx)) {
300+
} else if indices[..i].contains(&Some(idx)) {
301301
return Err(GetDisjointMutError::OverlappingIndices);
302302
}
303303
}

src/map/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ fn disjoint_indices_mut_fail_duplicate() {
10021002
map.insert(1, 10);
10031003
map.insert(321, 20);
10041004
assert_eq!(
1005-
map.get_disjoint_indices_mut([1, 2, 1]),
1005+
map.get_disjoint_indices_mut([1, 0, 1]),
10061006
Err(crate::GetDisjointMutError::OverlappingIndices)
10071007
);
10081008
}

0 commit comments

Comments
 (0)