about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-03-11 17:20:20 +0000
committerbors <bors@rust-lang.org>2019-03-11 17:20:20 +0000
commite68bf8ae15ee6c052d0bcc9252386c5c5ee86de2 (patch)
tree09d79ac31cde6e8ea6f1d8da98b7a33d34ab945e /src
parentde5c3c4b07fb37028bb36b2271271caf24eec6f3 (diff)
parenta03e20db6d15fe1cdda64c0fbe934e36209a08f6 (diff)
downloadrust-e68bf8ae15ee6c052d0bcc9252386c5c5ee86de2.tar.gz
rust-e68bf8ae15ee6c052d0bcc9252386c5c5ee86de2.zip
Auto merge of #58021 - ishitatsuyuki:57667-fix, r=RalfJung
Fix fallout from #57667
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/ptr.rs39
1 files changed, 6 insertions, 33 deletions
diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs
index bc43630ae59..9afcb7c4621 100644
--- a/src/libsyntax/ptr.rs
+++ b/src/libsyntax/ptr.rs
@@ -29,7 +29,7 @@
 use std::fmt::{self, Display, Debug};
 use std::iter::FromIterator;
 use std::ops::{Deref, DerefMut};
-use std::{mem, ptr, slice, vec};
+use std::{slice, vec};
 
 use serialize::{Encodable, Decodable, Encoder, Decoder};
 
@@ -66,45 +66,18 @@ impl<T: 'static> P<T> {
     pub fn map<F>(mut self, f: F) -> P<T> where
         F: FnOnce(T) -> T,
     {
-        let p: *mut T = &mut *self.ptr;
+        let x = f(*self.ptr);
+        *self.ptr = x;
 
-        // Leak self in case of panic.
-        // FIXME(eddyb) Use some sort of "free guard" that
-        // only deallocates, without dropping the pointee,
-        // in case the call the `f` below ends in a panic.
-        mem::forget(self);
-
-        unsafe {
-            ptr::write(p, f(ptr::read(p)));
-
-            // Recreate self from the raw pointer.
-            P { ptr: Box::from_raw(p) }
-        }
+        self
     }
 
     /// Optionally produce a new `P<T>` from `self` without reallocating.
     pub fn filter_map<F>(mut self, f: F) -> Option<P<T>> where
         F: FnOnce(T) -> Option<T>,
     {
-        let p: *mut T = &mut *self.ptr;
-
-        // Leak self in case of panic.
-        // FIXME(eddyb) Use some sort of "free guard" that
-        // only deallocates, without dropping the pointee,
-        // in case the call the `f` below ends in a panic.
-        mem::forget(self);
-
-        unsafe {
-            if let Some(v) = f(ptr::read(p)) {
-                ptr::write(p, v);
-
-                // Recreate self from the raw pointer.
-                Some(P { ptr: Box::from_raw(p) })
-            } else {
-                drop(Box::from_raw(p));
-                None
-            }
-        }
+        *self.ptr = f(*self.ptr)?;
+        Some(self)
     }
 }