use core::hash::{Hash, Hasher};
use core::intrinsics::abort;
use core::marker;
-use core::marker::Unsize;
+use core::marker::{Unsize, PhantomData};
use core::mem::{self, align_of_val, forget, size_of_val, uninitialized};
use core::ops::Deref;
use core::ops::CoerceUnsized;
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Rc<T: ?Sized> {
ptr: Shared<RcBox<T>>,
+ phantom: PhantomData<T>,
}
#[stable(feature = "rust1", since = "1.0.0")]
weak: Cell::new(1),
value,
})),
+ phantom: PhantomData,
}
}
unsafe {
let val = ptr::read(&*this); // copy the contained object
- // Indicate to Weaks that they can't be promoted by decrememting
+ // Indicate to Weaks that they can't be promoted by decrementing
// the strong count, and then remove the implicit "strong weak"
// pointer while also handling drop logic by just crafting a
// fake Weak.
Rc {
ptr: Shared::new_unchecked(rc_ptr),
+ phantom: PhantomData,
}
}
forget(self);
Ok(Rc {
ptr: Shared::new_unchecked(raw as *const RcBox<T> as *mut _),
+ phantom: PhantomData,
})
}
} else {
// Free the allocation without dropping its contents
box_free(bptr);
- Rc { ptr: Shared::new_unchecked(ptr) }
+ Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
}
}
}
&mut (*ptr).value as *mut [T] as *mut T,
v.len());
- Rc { ptr: Shared::new_unchecked(ptr) }
+ Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
}
}
// All clear. Forget the guard so it doesn't free the new RcBox.
forget(guard);
- Rc { ptr: Shared::new_unchecked(ptr) }
+ Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
}
}
}
#[inline]
fn clone(&self) -> Rc<T> {
self.inc_strong();
- Rc { ptr: self.ptr }
+ Rc { ptr: self.ptr, phantom: PhantomData }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> fmt::Pointer for Rc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- fmt::Pointer::fmt(&self.ptr, f)
+ fmt::Pointer::fmt(&(&**self as *const T), f)
}
}
impl<'a> From<&'a str> for Rc<str> {
#[inline]
fn from(v: &str) -> Rc<str> {
- unsafe { mem::transmute(<Rc<[u8]>>::from(v.as_bytes())) }
+ let rc = Rc::<[u8]>::from(v.as_bytes());
+ unsafe { Rc::from_raw(Rc::into_raw(rc) as *const str) }
}
}
None
} else {
self.inc_strong();
- Some(Rc { ptr: self.ptr })
+ Some(Rc { ptr: self.ptr, phantom: PhantomData })
}
}
}