Skip to content

Commit e793bd2

Browse files
committed
Make RawTable::drain safe
The documentation indicated a safety question of the lifetime, but there is a lifetime parameter on `RawDrain` to ensure that. Also, the similar `par_drain` is already a safe method.
1 parent 0f38616 commit e793bd2

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/map.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,8 @@ impl<K, V, S> HashMap<K, V, S> {
548548
/// ```
549549
#[cfg_attr(feature = "inline-more", inline)]
550550
pub fn drain(&mut self) -> Drain<'_, K, V> {
551-
// Here we tie the lifetime of self to the iter.
552-
unsafe {
553-
Drain {
554-
inner: self.table.drain(),
555-
}
551+
Drain {
552+
inner: self.table.drain(),
556553
}
557554
}
558555

src/raw/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,14 +1062,12 @@ impl<T> RawTable<T> {
10621062

10631063
/// Returns an iterator which removes all elements from the table without
10641064
/// freeing the memory.
1065-
///
1066-
/// It is up to the caller to ensure that the `RawTable` outlives the `RawDrain`.
1067-
/// Because we cannot make the `next` method unsafe on the `RawDrain`,
1068-
/// we have to make the `drain` method unsafe.
10691065
#[cfg_attr(feature = "inline-more", inline)]
1070-
pub unsafe fn drain(&mut self) -> RawDrain<'_, T> {
1071-
let iter = self.iter();
1072-
self.drain_iter_from(iter)
1066+
pub fn drain(&mut self) -> RawDrain<'_, T> {
1067+
unsafe {
1068+
let iter = self.iter();
1069+
self.drain_iter_from(iter)
1070+
}
10731071
}
10741072

10751073
/// Returns an iterator which removes all elements from the table without

0 commit comments

Comments
 (0)