Auto merge of #7523 - eefriedman:unnecessary-unsafe, r=SimonSapin

Fix up some unnecessary uses of `unsafe`.



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7523)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-09 00:05:17 -06:00
commit be9a9ffda1
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 {

View file

@ -6,7 +6,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
static mut next_tid: AtomicUsize = ATOMIC_USIZE_INIT;
static NEXT_TID: AtomicUsize = ATOMIC_USIZE_INIT;
thread_local!(static TASK_LOCAL_TID: Rc<RefCell<Option<usize>>> = Rc::new(RefCell::new(None)));
@ -15,7 +15,7 @@ pub fn tid() -> usize {
TASK_LOCAL_TID.with(|ref k| {
let ret =
match *k.borrow() {
None => unsafe { next_tid.fetch_add(1, Ordering::SeqCst) },
None => NEXT_TID.fetch_add(1, Ordering::SeqCst),
Some(x) => x,
};