Skip to content

Commit c94b3f1

Browse files
committed
Replace the forget intrinsic with ManuallyDrop
less intrinsics = better life
1 parent 3871312 commit c94b3f1

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/libcore/intrinsics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,6 @@ extern "rust-intrinsic" {
691691
/// initialize memory previous set to the result of `uninit`.
692692
pub fn uninit<T>() -> T;
693693

694-
/// Moves a value out of scope without running drop glue.
695-
pub fn forget<T>(_: T) -> ();
696-
697694
/// Reinterprets the bits of a value of one type as another type.
698695
///
699696
/// Both types must have the same size. Neither the original, nor the result,

src/libcore/mem.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub use intrinsics::transmute;
171171
#[inline]
172172
#[stable(feature = "rust1", since = "1.0.0")]
173173
pub fn forget<T>(t: T) {
174-
unsafe { intrinsics::forget(t) }
174+
ManuallyDrop::new(t);
175175
}
176176

177177
/// Returns the size of a type in bytes.
@@ -780,12 +780,14 @@ pub union ManuallyDrop<T>{ value: T }
780780
impl<T> ManuallyDrop<T> {
781781
/// Wrap a value to be manually dropped.
782782
#[unstable(feature = "manually_drop", issue = "40673")]
783+
#[inline]
783784
pub fn new(value: T) -> ManuallyDrop<T> {
784785
ManuallyDrop { value: value }
785786
}
786787

787788
/// Extract the value from the ManuallyDrop container.
788789
#[unstable(feature = "manually_drop", issue = "40673")]
790+
#[inline]
789791
pub fn into_inner(self) -> T {
790792
unsafe {
791793
self.value
@@ -800,6 +802,7 @@ impl<T> ManuallyDrop<T> {
800802
/// now represents uninitialized data. It is up to the user of this method to ensure the
801803
/// uninitialized data is not actually used.
802804
#[unstable(feature = "manually_drop", issue = "40673")]
805+
#[inline]
803806
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
804807
ptr::drop_in_place(&mut slot.value)
805808
}
@@ -808,6 +811,7 @@ impl<T> ManuallyDrop<T> {
808811
#[unstable(feature = "manually_drop", issue = "40673")]
809812
impl<T> ::ops::Deref for ManuallyDrop<T> {
810813
type Target = T;
814+
#[inline]
811815
fn deref(&self) -> &Self::Target {
812816
unsafe {
813817
&self.value
@@ -817,6 +821,7 @@ impl<T> ::ops::Deref for ManuallyDrop<T> {
817821

818822
#[unstable(feature = "manually_drop", issue = "40673")]
819823
impl<T> ::ops::DerefMut for ManuallyDrop<T> {
824+
#[inline]
820825
fn deref_mut(&mut self) -> &mut Self::Target {
821826
unsafe {
822827
&mut self.value

src/librustc_trans/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
188188
C_nil(ccx)
189189
}
190190
// Effectively no-ops
191-
"uninit" | "forget" => {
191+
"uninit" => {
192192
C_nil(ccx)
193193
}
194194
"needs_drop" => {

src/librustc_typeck/check/intrinsic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
124124
"rustc_peek" => (1, vec![param(0)], param(0)),
125125
"init" => (1, Vec::new(), param(0)),
126126
"uninit" => (1, Vec::new(), param(0)),
127-
"forget" => (1, vec![ param(0) ], tcx.mk_nil()),
128127
"transmute" => (2, vec![ param(0) ], param(1)),
129128
"move_val_init" => {
130129
(1,

0 commit comments

Comments
 (0)