Skip to content

Commit

Permalink
Auto merge of #372 - Amanieu:unsafe-deprecated, r=Amanieu
Browse files Browse the repository at this point in the history
Remove `Bucket` and `RawTable` that are hard to use safely

This removes the following methods in favor of better alternatives:
- `RawTable::erase_no_drop` => Use `RawTable::erase` or `RawTable::remove` instead.
- `Bucket::read` => Use `RawTable::remove` instead.
- `Bucket::drop` => Use `RawTable::erase` instead.
- `Bucket::write` => Use `Bucket::as_mut` instead.

Fixes #364
  • Loading branch information
bors committed Nov 9, 2022
2 parents bf272b6 + 3263559 commit 37071e5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/raw/mod.rs
Expand Up @@ -340,15 +340,15 @@ impl<T> Bucket<T> {
}
}
#[cfg_attr(feature = "inline-more", inline)]
pub unsafe fn drop(&self) {
pub(crate) unsafe fn drop(&self) {
self.as_ptr().drop_in_place();
}
#[inline]
pub unsafe fn read(&self) -> T {
pub(crate) unsafe fn read(&self) -> T {
self.as_ptr().read()
}
#[inline]
pub unsafe fn write(&self, val: T) {
pub(crate) unsafe fn write(&self, val: T) {
self.as_ptr().write(val);
}
#[inline]
Expand Down Expand Up @@ -550,16 +550,14 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {

/// Erases an element from the table without dropping it.
#[cfg_attr(feature = "inline-more", inline)]
#[deprecated(since = "0.8.1", note = "use erase or remove instead")]
pub unsafe fn erase_no_drop(&mut self, item: &Bucket<T>) {
unsafe fn erase_no_drop(&mut self, item: &Bucket<T>) {
let index = self.bucket_index(item);
self.table.erase(index);
}

/// Erases an element from the table, dropping it in place.
#[cfg_attr(feature = "inline-more", inline)]
#[allow(clippy::needless_pass_by_value)]
#[allow(deprecated)]
pub unsafe fn erase(&mut self, item: Bucket<T>) {
// Erase the element from the table first since drop might panic.
self.erase_no_drop(&item);
Expand All @@ -585,7 +583,6 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
/// Removes an element from the table, returning it.
#[cfg_attr(feature = "inline-more", inline)]
#[allow(clippy::needless_pass_by_value)]
#[allow(deprecated)]
pub unsafe fn remove(&mut self, item: Bucket<T>) -> T {
self.erase_no_drop(&item);
item.read()
Expand Down

0 comments on commit 37071e5

Please sign in to comment.