Replace the forget
intrinsic with ManuallyDrop
less intrinsics = better life
This commit is contained in:
parent
38713126dd
commit
c94b3f1266
@ -691,9 +691,6 @@
|
||||
/// initialize memory previous set to the result of `uninit`.
|
||||
pub fn uninit<T>() -> T;
|
||||
|
||||
/// Moves a value out of scope without running drop glue.
|
||||
pub fn forget<T>(_: T) -> ();
|
||||
|
||||
/// Reinterprets the bits of a value of one type as another type.
|
||||
///
|
||||
/// Both types must have the same size. Neither the original, nor the result,
|
||||
|
@ -171,7 +171,7 @@
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn forget<T>(t: T) {
|
||||
unsafe { intrinsics::forget(t) }
|
||||
ManuallyDrop::new(t);
|
||||
}
|
||||
|
||||
/// Returns the size of a type in bytes.
|
||||
@ -780,12 +780,14 @@ pub union ManuallyDrop<T>{ value: T }
|
||||
impl<T> ManuallyDrop<T> {
|
||||
/// Wrap a value to be manually dropped.
|
||||
#[unstable(feature = "manually_drop", issue = "40673")]
|
||||
#[inline]
|
||||
pub fn new(value: T) -> ManuallyDrop<T> {
|
||||
ManuallyDrop { value: value }
|
||||
}
|
||||
|
||||
/// Extract the value from the ManuallyDrop container.
|
||||
#[unstable(feature = "manually_drop", issue = "40673")]
|
||||
#[inline]
|
||||
pub fn into_inner(self) -> T {
|
||||
unsafe {
|
||||
self.value
|
||||
@ -800,6 +802,7 @@ pub fn into_inner(self) -> T {
|
||||
/// now represents uninitialized data. It is up to the user of this method to ensure the
|
||||
/// uninitialized data is not actually used.
|
||||
#[unstable(feature = "manually_drop", issue = "40673")]
|
||||
#[inline]
|
||||
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
|
||||
ptr::drop_in_place(&mut slot.value)
|
||||
}
|
||||
@ -808,6 +811,7 @@ pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
|
||||
#[unstable(feature = "manually_drop", issue = "40673")]
|
||||
impl<T> ::ops::Deref for ManuallyDrop<T> {
|
||||
type Target = T;
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe {
|
||||
&self.value
|
||||
@ -817,6 +821,7 @@ fn deref(&self) -> &Self::Target {
|
||||
|
||||
#[unstable(feature = "manually_drop", issue = "40673")]
|
||||
impl<T> ::ops::DerefMut for ManuallyDrop<T> {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
unsafe {
|
||||
&mut self.value
|
||||
|
@ -188,7 +188,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||
C_nil(ccx)
|
||||
}
|
||||
// Effectively no-ops
|
||||
"uninit" | "forget" => {
|
||||
"uninit" => {
|
||||
C_nil(ccx)
|
||||
}
|
||||
"needs_drop" => {
|
||||
|
@ -124,7 +124,6 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
"rustc_peek" => (1, vec![param(0)], param(0)),
|
||||
"init" => (1, Vec::new(), param(0)),
|
||||
"uninit" => (1, Vec::new(), param(0)),
|
||||
"forget" => (1, vec![ param(0) ], tcx.mk_nil()),
|
||||
"transmute" => (2, vec![ param(0) ], param(1)),
|
||||
"move_val_init" => {
|
||||
(1,
|
||||
|
Loading…
Reference in New Issue
Block a user