Fix up some unnecessary uses of unsafe.

This commit is contained in:
Eli Friedman 2015-08-11 17:44:21 -07:00
parent da02dba979
commit 94dec69247
8 changed files with 208 additions and 226 deletions

View file

@ -4,7 +4,6 @@
//! A persistent, thread-safe singly-linked list.
use std::mem;
use std::sync::Arc;
pub struct PersistentList<T> {
@ -81,15 +80,7 @@ impl<'a, T> Iterator for PersistentListIterator<'a, T> where T: Send + Sync + 's
fn next(&mut self) -> Option<&'a T> {
let entry = match self.entry {
None => return None,
Some(entry) => {
// This `transmute` is necessary to ensure that the lifetimes of the next entry and
// this entry match up; the compiler doesn't know this, but we do because of the
// reference counting behavior of `Arc`.
unsafe {
mem::transmute::<&'a PersistentListEntry<T>,
&'static PersistentListEntry<T>>(entry)
}
}
Some(entry) => entry,
};
let value = &entry.value;
self.entry = match entry.next {