]> git.lizzy.rs Git - rust.git/commitdiff
std: clean up ptr a bit
authorCorey Richardson <corey@octayn.net>
Fri, 14 Feb 2014 23:42:01 +0000 (18:42 -0500)
committerCorey Richardson <corey@octayn.net>
Sat, 15 Feb 2014 17:11:41 +0000 (12:11 -0500)
25 files changed:
src/doc/guide-ffi.md
src/libcollections/dlist.rs
src/librustc/middle/ty.rs
src/libstd/io/test.rs
src/libstd/managed.rs
src/libstd/ptr.rs
src/libstd/rc.rs
src/libstd/repr.rs
src/libstd/sync/deque.rs
src/libstd/task.rs
src/libstd/vec.rs
src/libstd/vec_ng.rs
src/test/compile-fail/issue-3096-2.rs
src/test/run-pass/borrowck-borrow-from-expr-block.rs
src/test/run-pass/borrowck-preserve-box-in-field.rs
src/test/run-pass/borrowck-preserve-box-in-uniq.rs
src/test/run-pass/borrowck-preserve-box.rs
src/test/run-pass/borrowck-preserve-expl-deref.rs
src/test/run-pass/cap-clause-move.rs [deleted file]
src/test/run-pass/const-region-ptrs-noncopy.rs
src/test/run-pass/enum-alignment.rs
src/test/run-pass/stable-addr-of.rs
src/test/run-pass/swap-overlapping.rs
src/test/run-pass/task-spawn-move-and-copy.rs
src/test/run-pass/uniq-cc-generic.rs

index 053a8612694ab399aff710291f4f3af61e05d1f7..c279ff314b474454dc961a5c2fa4949610c88eaa 100644 (file)
@@ -229,7 +229,7 @@ impl<T: Send> Drop for Unique<T> {
             let x = mem::uninit(); // dummy value to swap in
             // We need to move the object out of the box, so that
             // the destructor is called (at the end of this scope.)
-            ptr::replace_ptr(self.ptr, x);
+            ptr::replace(self.ptr, x);
             free(self.ptr as *mut c_void)
         }
     }
@@ -306,7 +306,7 @@ which would call back to `callback()` in Rust.
 The former example showed how a global function can be called from C code.
 However it is often desired that the callback is targetted to a special
 Rust object. This could be the object that represents the wrapper for the
-respective C object. 
+respective C object.
 
 This can be achieved by passing an unsafe pointer to the object down to the
 C library. The C library can then include the pointer to the Rust object in
@@ -335,7 +335,7 @@ extern {
 fn main() {
     // Create the object that will be referenced in the callback
     let rust_object = ~RustObject{a: 5, ...};
-     
+
     unsafe {
         // Gets a raw pointer to the object
         let target_addr:*RustObject = ptr::to_unsafe_ptr(rust_object);
@@ -380,8 +380,8 @@ Rust is to use channels (in `std::comm`) to forward data from the C thread
 that invoked the callback into a Rust task.
 
 If an asychronous callback targets a special object in the Rust address space
-it is also absolutely necessary that no more callbacks are performed by the 
-C library after the respective Rust object gets destroyed. 
+it is also absolutely necessary that no more callbacks are performed by the
+C library after the respective Rust object gets destroyed.
 This can be achieved by unregistering the callback in the object's
 destructor and designing the library in a way that guarantees that no
 callback will be performed after unregistration.
index 15e2303bd8502821379c624f166ef4cefa5d917c..28e7b9460dc7aee9571b64829d2d491d81ee2fd7 100644 (file)
@@ -83,7 +83,7 @@ fn none() -> Rawlink<T> {
 
     /// Like Option::Some for Rawlink
     fn some(n: &mut T) -> Rawlink<T> {
-        Rawlink{p: ptr::to_mut_unsafe_ptr(n)}
+        Rawlink{p: n}
     }
 
     /// Convert the `Rawlink` into an Option value
index 22ed9b5010f83070b8bb57f7e52de82732f46ae8..374f49a36be5e7144ebb6d431646a1d3f62d6254 100644 (file)
@@ -33,7 +33,6 @@
 use std::cmp;
 use std::hashmap::{HashMap, HashSet};
 use std::ops;
-use std::ptr::to_unsafe_ptr;
 use std::rc::Rc;
 use std::to_bytes;
 use std::to_str::ToStr;
@@ -1137,7 +1136,7 @@ pub fn mk_t(cx: ctxt, st: sty) -> t {
         _ => {}
     };
 
-    let key = intern_key { sty: to_unsafe_ptr(&st) };
+    let key = intern_key { sty: &st };
 
     {
         let mut interner = cx.interner.borrow_mut();
@@ -1234,7 +1233,7 @@ fn sflags(substs: &substs) -> uint {
         flags: flags,
     };
 
-    let sty_ptr = to_unsafe_ptr(&t.sty);
+    let sty_ptr = &t.sty as *sty;
 
     let key = intern_key {
         sty: sty_ptr,
index 6ac73e7f61e712c78a810bd16968562313786cd6..04ecb479060c4e46f68acfbe7782f64b7c4646a5 100644 (file)
@@ -155,7 +155,7 @@ fn sysctl(name: *mut libc::c_int, namelen: libc::c_uint,
     pub unsafe fn raise_fd_limit() {
         // The strategy here is to fetch the current resource limits, read the kern.maxfilesperproc
         // sysctl value, and bump the soft resource limit for maxfiles up to the sysctl value.
-        use ptr::{to_unsafe_ptr, to_mut_unsafe_ptr, mut_null};
+        use ptr::mut_null;
         use mem::size_of_val;
         use os::last_os_error;
 
@@ -163,9 +163,7 @@ pub unsafe fn raise_fd_limit() {
         let mut mib: [libc::c_int, ..2] = [CTL_KERN, KERN_MAXFILESPERPROC];
         let mut maxfiles: libc::c_int = 0;
         let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
-        if sysctl(to_mut_unsafe_ptr(&mut mib[0]), 2,
-                  to_mut_unsafe_ptr(&mut maxfiles) as *mut libc::c_void,
-                  to_mut_unsafe_ptr(&mut size),
+        if sysctl(&mut mib[0], 2, &mut maxfiles as *mut libc::c_int as *mut libc::c_void, &mut size,
                   mut_null(), 0) != 0 {
             let err = last_os_error();
             error!("raise_fd_limit: error calling sysctl: {}", err);
@@ -174,7 +172,7 @@ pub unsafe fn raise_fd_limit() {
 
         // Fetch the current resource limits
         let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0};
-        if getrlimit(RLIMIT_NOFILE, to_mut_unsafe_ptr(&mut rlim)) != 0 {
+        if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
             let err = last_os_error();
             error!("raise_fd_limit: error calling getrlimit: {}", err);
             return;
@@ -184,7 +182,7 @@ pub unsafe fn raise_fd_limit() {
         rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max);
 
         // Set our newly-increased resource limit
-        if setrlimit(RLIMIT_NOFILE, to_unsafe_ptr(&rlim)) != 0 {
+        if setrlimit(RLIMIT_NOFILE, &rlim) != 0 {
             let err = last_os_error();
             error!("raise_fd_limit: error calling setrlimit: {}", err);
             return;
index 914cc25250c7f6a5ab087b7d53ce8c430a738541..63196cd4f162efdb4261f007bc01f64567e57140 100644 (file)
@@ -10,8 +10,6 @@
 
 //! Operations on managed box types
 
-use ptr::to_unsafe_ptr;
-
 #[cfg(not(test))] use cmp::*;
 
 /// Returns the refcount of a shared box (as just before calling this)
@@ -24,8 +22,7 @@ pub fn refcount<T>(t: @T) -> uint {
 /// Determine if two shared boxes point to the same object
 #[inline]
 pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
-    let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
-    a_ptr == b_ptr
+    &*a as *T == &*b as *T
 }
 
 #[cfg(not(test))]
index 2ba6f7d4fd64d93fa45c48cb8753269b5d9151e9..037984d9e7fc775d1948f38976431fcd411551ef 100644 (file)
@@ -102,10 +102,10 @@ pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
 
 /**
  * Swap the values at two mutable locations of the same type, without
- * deinitialising or copying either one.
+ * deinitialising either. They may overlap.
  */
 #[inline]
-pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
+pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
     // Give ourselves some scratch space to work with
     let mut tmp: T = mem::uninit();
     let t: *mut T = &mut tmp;
@@ -122,19 +122,19 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
 
 /**
  * Replace the value at a mutable location with a new one, returning the old
- * value, without deinitialising or copying either one.
+ * value, without deinitialising either.
  */
 #[inline]
-pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
+pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
     mem::swap(cast::transmute(dest), &mut src); // cannot overlap
     src
 }
 
 /**
- * Reads the value from `*src` and returns it. Does not copy `*src`.
+ * Reads the value from `*src` and returns it.
  */
 #[inline(always)]
-pub unsafe fn read_ptr<T>(src: *T) -> T {
+pub unsafe fn read<T>(src: *T) -> T {
     let mut tmp: T = mem::uninit();
     copy_nonoverlapping_memory(&mut tmp, src, 1);
     tmp
@@ -145,9 +145,9 @@ pub unsafe fn read_ptr<T>(src: *T) -> T {
  * This currently prevents destructors from executing.
  */
 #[inline(always)]
-pub unsafe fn read_and_zero_ptr<T>(dest: *mut T) -> T {
+pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
     // Copy the data out from `dest`:
-    let tmp = read_ptr(&*dest);
+    let tmp = read(&*dest);
 
     // Now zero out `dest`:
     zero_memory(dest, 1);
@@ -155,18 +155,6 @@ pub unsafe fn read_and_zero_ptr<T>(dest: *mut T) -> T {
     tmp
 }
 
-/// Transform a region pointer - &T - to an unsafe pointer - *T.
-#[inline]
-pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
-    thing as *T
-}
-
-/// Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T.
-#[inline]
-pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
-    thing as *mut T
-}
-
 /**
   Given a **T (pointer to an array of pointers),
   iterate through each *T, up to the provided `len`,
@@ -176,7 +164,7 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
 */
 pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
     debug!("array_each_with_len: before iterate");
-    if arr as uint == 0 {
+    if arr.is_null() {
         fail!("ptr::array_each_with_len failure: arr input is null pointer");
     }
     //let start_ptr = *arr;
@@ -197,7 +185,7 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
   Dragons be here.
 */
 pub unsafe fn array_each<T>(arr: **T, cb: |*T|) {
-    if arr as uint == 0 {
+    if arr.is_null()  {
         fail!("ptr::array_each_with_len failure: arr input is null pointer");
     }
     let len = buf_len(arr);
@@ -205,100 +193,74 @@ pub unsafe fn array_each<T>(arr: **T, cb: |*T|) {
     array_each_with_len(arr, len, cb);
 }
 
-#[allow(missing_doc)]
+/// Extension methods for raw pointers.
 pub trait RawPtr<T> {
+    /// Returns the null pointer.
     fn null() -> Self;
+    /// Returns true if the pointer is equal to the null pointer.
     fn is_null(&self) -> bool;
-    fn is_not_null(&self) -> bool;
+    /// Returns true if the pointer is not equal to the null pointer.
+    fn is_not_null(&self) -> bool { !self.is_null() }
+    /// Returns the value of this pointer (ie, the address it points to)
     fn to_uint(&self) -> uint;
+    /// Returns `None` if the pointer is null, or else returns the value wrapped
+    /// in `Some`.
+    ///
+    /// # Safety Notes
+    ///
+    /// While this method is useful for null-safety, it is important to note
+    /// that this is still an unsafe operation because the returned value could
+    /// be pointing to invalid memory.
     unsafe fn to_option(&self) -> Option<&T>;
+    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+    /// the object, or one-byte-past-the-end.
     unsafe fn offset(self, count: int) -> Self;
 }
 
-/// Extension methods for immutable pointers
 impl<T> RawPtr<T> for *T {
-    /// Returns the null pointer.
     #[inline]
     fn null() -> *T { null() }
 
-    /// Returns true if the pointer is equal to the null pointer.
     #[inline]
     fn is_null(&self) -> bool { *self == RawPtr::null() }
 
-    /// Returns true if the pointer is not equal to the null pointer.
     #[inline]
-    fn is_not_null(&self) -> bool { *self != RawPtr::null() }
+    fn to_uint(&self) -> uint { *self as uint }
 
-    /// Returns the address of this pointer.
     #[inline]
-    fn to_uint(&self) -> uint { *self as uint }
+    unsafe fn offset(self, count: int) -> *T { intrinsics::offset(self, count) }
 
-    ///
-    /// Returns `None` if the pointer is null, or else returns the value wrapped
-    /// in `Some`.
-    ///
-    /// # Safety Notes
-    ///
-    /// While this method is useful for null-safety, it is important to note
-    /// that this is still an unsafe operation because the returned value could
-    /// be pointing to invalid memory.
-    ///
     #[inline]
     unsafe fn to_option(&self) -> Option<&T> {
-        if self.is_null() { None } else {
+        if self.is_null() {
+            None
+        } else {
             Some(cast::transmute(*self))
         }
     }
-
-    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
-    /// the object, or one-byte-past-the-end.
-    #[inline]
-    unsafe fn offset(self, count: int) -> *T { intrinsics::offset(self, count) }
 }
 
-/// Extension methods for mutable pointers
 impl<T> RawPtr<T> for *mut T {
-    /// Returns the null pointer.
     #[inline]
     fn null() -> *mut T { mut_null() }
 
-    /// Returns true if the pointer is equal to the null pointer.
     #[inline]
     fn is_null(&self) -> bool { *self == RawPtr::null() }
 
-    /// Returns true if the pointer is not equal to the null pointer.
     #[inline]
-    fn is_not_null(&self) -> bool { *self != RawPtr::null() }
+    fn to_uint(&self) -> uint { *self as uint }
 
-    /// Returns the address of this pointer.
     #[inline]
-    fn to_uint(&self) -> uint { *self as uint }
+    unsafe fn offset(self, count: int) -> *mut T { intrinsics::offset(self as *T, count) as *mut T }
 
-    ///
-    /// Returns `None` if the pointer is null, or else returns the value wrapped
-    /// in `Some`.
-    ///
-    /// # Safety Notes
-    ///
-    /// While this method is useful for null-safety, it is important to note
-    /// that this is still an unsafe operation because the returned value could
-    /// be pointing to invalid memory.
-    ///
     #[inline]
     unsafe fn to_option(&self) -> Option<&T> {
-        if self.is_null() { None } else {
+        if self.is_null() {
+            None
+        } else {
             Some(cast::transmute(*self))
         }
     }
-
-    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
-    /// the object, or one-byte-past-the-end. An arithmetic overflow is also
-    /// undefined behaviour.
-    ///
-    /// This method should be preferred over `offset` when the guarantee can be
-    /// satisfied, to enable better optimization.
-    #[inline]
-    unsafe fn offset(self, count: int) -> *mut T { intrinsics::offset(self as *T, count) as *mut T }
 }
 
 // Equality for pointers
index a1565bc85dede8c4fb5e9bcee0f64e5eedad73ff..ea3d5e0edac0186e3f04214c3a3ff1c0567dc67b 100644 (file)
 */
 
 use cast::transmute;
-use ops::Drop;
-use cmp::{Eq, Ord};
 use clone::{Clone, DeepClone};
+use cmp::{Eq, Ord};
 use kinds::marker;
-use rt::global_heap::exchange_free;
-use ptr::read_ptr;
+use ops::Drop;
 use option::{Option, Some, None};
+use ptr;
+use rt::global_heap::exchange_free;
 
 struct RcBox<T> {
     value: T,
@@ -85,7 +85,7 @@ fn drop(&mut self) {
             if self.ptr != 0 as *mut RcBox<T> {
                 (*self.ptr).strong -= 1;
                 if (*self.ptr).strong == 0 {
-                    read_ptr(self.borrow()); // destroy the contained object
+                    ptr::read(self.borrow()); // destroy the contained object
 
                     // remove the implicit "strong weak" pointer now
                     // that we've destroyed the contents.
index 58c00177b90165578dd5f0bf23000352ee355125..fb2053ddaf61594206962cec3d1f7e158e8c9f1a 100644 (file)
@@ -22,7 +22,6 @@
 use io;
 use iter::Iterator;
 use option::{Some, None, Option};
-use ptr;
 use ptr::RawPtr;
 use reflect;
 use reflect::{MovePtr, align};
@@ -230,7 +229,7 @@ pub fn write_vec_range(&mut self, ptr: *(), len: uint, inner: *TyDesc) -> bool {
     }
 
     pub fn write_unboxed_vec_repr(&mut self, _: uint, v: &raw::Vec<()>, inner: *TyDesc) -> bool {
-        self.write_vec_range(ptr::to_unsafe_ptr(&v.data), v.fill, inner)
+        self.write_vec_range(&v.data, v.fill, inner)
     }
 
     fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool {
@@ -319,7 +318,7 @@ fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
         if_ok!(self, self.writer.write(['@' as u8]));
         self.write_mut_qualifier(mtbl);
         self.get::<&raw::Box<()>>(|this, b| {
-            let p = ptr::to_unsafe_ptr(&b.data) as *u8;
+            let p = &b.data as *() as *u8;
             this.visit_ptr_inner(p, inner)
         })
     }
@@ -387,7 +386,7 @@ fn visit_evec_fixed(&mut self, n: uint, sz: uint, _align: uint,
                         _: uint, inner: *TyDesc) -> bool {
         let assumed_size = if sz == 0 { n } else { sz };
         self.get::<()>(|this, b| {
-            this.write_vec_range(ptr::to_unsafe_ptr(b), assumed_size, inner)
+            this.write_vec_range(b, assumed_size, inner)
         })
     }
 
@@ -606,7 +605,7 @@ fn visit_self(&mut self) -> bool { true }
 
 pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> {
     unsafe {
-        let ptr = ptr::to_unsafe_ptr(object) as *u8;
+        let ptr = object as *T as *u8;
         let tydesc = get_tydesc::<T>();
         let u = ReprVisitor(ptr, writer);
         let mut v = reflect::MovePtrAdaptor(u);
index 7feff127d691a029511e7af37995d1b7b6bfc761..7ce760040e65ec0046b1ecc35665761e6cbff202 100644 (file)
@@ -363,7 +363,7 @@ fn mask(&self) -> int { (1 << self.log_size) - 1 }
     // very unsafe method which the caller needs to treat specially in case a
     // race is lost.
     unsafe fn get(&self, i: int) -> T {
-        ptr::read_ptr(self.storage.offset(i & self.mask()))
+        ptr::read(self.storage.offset(i & self.mask()))
     }
 
     // Unsafe because this unsafely overwrites possibly uninitialized or
index 5d8c4a87b39357e1028f1e5036b9fcc48e5d38d8..1cdf5998e8b203cfe1bf983d1b12ef6e41110e09 100644 (file)
@@ -509,10 +509,10 @@ fn avoid_copying_the_body(spawnfn: |v: proc()|) {
     let (p, ch) = Chan::<uint>::new();
 
     let x = ~1;
-    let x_in_parent = ptr::to_unsafe_ptr(&*x) as uint;
+    let x_in_parent = (&*x) as *int as uint;
 
     spawnfn(proc() {
-        let x_in_child = ptr::to_unsafe_ptr(&*x) as uint;
+        let x_in_child = (&*x) as *int as uint;
         ch.send(x_in_child);
     });
 
index cfe2ad5a08af439be66c523ef57d28b831388b2c..f8f9f82b657a5830784598b5ad59b7a722ff1fc5 100644 (file)
 #[warn(non_camel_case_types)];
 
 use cast;
+use cast::transmute;
 use ops::Drop;
 use clone::{Clone, DeepClone};
 use container::{Container, Mutable};
 use iter::*;
 use num::{Integer, CheckedAdd, Saturating, checked_next_power_of_two};
 use option::{None, Option, Some};
-use ptr::to_unsafe_ptr;
 use ptr;
 use ptr::RawPtr;
 use rt::global_heap::{malloc_raw, realloc_raw, exchange_free};
@@ -188,7 +188,7 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
         let ptr = malloc_raw(size) as *mut Vec<()>;
         (*ptr).alloc = alloc;
         (*ptr).fill = 0;
-        cast::transmute(ptr)
+        transmute(ptr)
     }
 }
 
@@ -216,7 +216,7 @@ pub fn build<A>(size: Option<uint>, builder: |push: |v: A||) -> ~[A] {
  */
 pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
     unsafe {
-        cast::transmute(Slice { data: s, len: 1 })
+        transmute(Slice { data: s, len: 1 })
     }
 }
 
@@ -225,8 +225,8 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] {
  */
 pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] {
     unsafe {
-        let ptr: *A = cast::transmute(s);
-        cast::transmute(Slice { data: ptr, len: 1 })
+        let ptr: *A = transmute(s);
+        transmute(Slice { data: ptr, len: 1 })
     }
 }
 
@@ -991,7 +991,7 @@ fn slice(&self, start: uint, end: uint) -> &'a [T] {
         assert!(start <= end);
         assert!(end <= self.len());
         unsafe {
-            cast::transmute(Slice {
+            transmute(Slice {
                     data: self.as_ptr().offset(start as int),
                     len: (end - start)
                 })
@@ -1109,7 +1109,7 @@ fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U] {
 
     #[inline]
     unsafe fn unsafe_ref(self, index: uint) -> &'a T {
-        cast::transmute(self.repr().data.offset(index as int))
+        transmute(self.repr().data.offset(index as int))
     }
 
     #[inline]
@@ -1144,7 +1144,7 @@ fn map<U>(&self, f: |t: &T| -> U) -> ~[U] {
     fn shift_ref(&mut self) -> Option<&'a T> {
         if self.len() == 0 { return None; }
         unsafe {
-            let s: &mut Slice<T> = cast::transmute(self);
+            let s: &mut Slice<T> = transmute(self);
             Some(&*raw::shift_ptr(s))
         }
     }
@@ -1152,7 +1152,7 @@ fn shift_ref(&mut self) -> Option<&'a T> {
     fn pop_ref(&mut self) -> Option<&'a T> {
         if self.len() == 0 { return None; }
         unsafe {
-            let s: &mut Slice<T> = cast::transmute(self);
+            let s: &mut Slice<T> = transmute(self);
             Some(&*raw::pop_ptr(s))
         }
     }
@@ -1417,8 +1417,8 @@ impl<T> OwnedVector<T> for ~[T] {
     #[inline]
     fn move_iter(self) -> MoveItems<T> {
         unsafe {
-            let iter = cast::transmute(self.iter());
-            let ptr = cast::transmute(self);
+            let iter = transmute(self.iter());
+            let ptr = transmute(self);
             MoveItems { allocation: ptr, iter: iter }
         }
     }
@@ -1432,7 +1432,7 @@ fn reserve_exact(&mut self, n: uint) {
         // Only make the (slow) call into the runtime if we have to
         if self.capacity() < n {
             unsafe {
-                let ptr: *mut *mut Vec<()> = cast::transmute(self);
+                let ptr: *mut *mut Vec<()> = transmute(self);
                 let alloc = n * mem::nonzero_size_of::<T>();
                 let size = alloc + mem::size_of::<Vec<()>>();
                 if alloc / mem::nonzero_size_of::<T>() != n || size < alloc {
@@ -1463,14 +1463,14 @@ fn reserve_additional(&mut self, n: uint) {
     #[inline]
     fn capacity(&self) -> uint {
         unsafe {
-            let repr: **Vec<()> = cast::transmute(self);
+            let repr: **Vec<()> = transmute(self);
             (**repr).alloc / mem::nonzero_size_of::<T>()
         }
     }
 
     fn shrink_to_fit(&mut self) {
         unsafe {
-            let ptr: *mut *mut Vec<()> = cast::transmute(self);
+            let ptr: *mut *mut Vec<()> = transmute(self);
             let alloc = (**ptr).fill;
             let size = alloc + mem::size_of::<Vec<()>>();
             *ptr = realloc_raw(*ptr as *mut u8, size) as *mut Vec<()>;
@@ -1481,7 +1481,7 @@ fn shrink_to_fit(&mut self) {
     #[inline]
     fn push(&mut self, t: T) {
         unsafe {
-            let repr: **Vec<()> = cast::transmute(&mut *self);
+            let repr: **Vec<()> = transmute(&mut *self);
             let fill = (**repr).fill;
             if (**repr).alloc <= fill {
                 self.reserve_additional(1);
@@ -1493,10 +1493,10 @@ fn push(&mut self, t: T) {
         // This doesn't bother to make sure we have space.
         #[inline] // really pretty please
         unsafe fn push_fast<T>(this: &mut ~[T], t: T) {
-            let repr: **mut Vec<u8> = cast::transmute(this);
+            let repr: **mut Vec<u8> = transmute(this);
             let fill = (**repr).fill;
             (**repr).fill += mem::nonzero_size_of::<T>();
-            let p = to_unsafe_ptr(&((**repr).data));
+            let p = &((**repr).data) as *u8;
             let p = p.offset(fill as int) as *mut T;
             mem::move_val_init(&mut(*p), t);
         }
@@ -1521,10 +1521,10 @@ fn pop(&mut self) -> Option<T> {
         match self.len() {
             0  => None,
             ln => {
-                let valptr = ptr::to_mut_unsafe_ptr(&mut self[ln - 1u]);
+                let valptr = &mut self[ln - 1u] as *mut T;
                 unsafe {
                     self.set_len(ln - 1u);
-                    Some(ptr::read_ptr(&*valptr))
+                    Some(ptr::read(&*valptr))
                 }
             }
         }
@@ -1568,7 +1568,7 @@ fn remove(&mut self, i: uint) -> Option<T> {
                 let ptr = self.as_mut_ptr().offset(i as int);
                 // copy it out, unsafely having a copy of the value on
                 // the stack and in the vector at the same time.
-                let ret = Some(ptr::read_ptr(ptr as *T));
+                let ret = Some(ptr::read(ptr as *T));
 
                 // Shift everything down to fill in that spot.
                 ptr::copy_memory(ptr, &*ptr.offset(1), len - i - 1);
@@ -1598,7 +1598,7 @@ fn truncate(&mut self, newlen: uint) {
             let p = self.as_mut_ptr();
             // This loop is optimized out for non-drop types.
             for i in range(newlen, oldlen) {
-                ptr::read_and_zero_ptr(p.offset(i as int));
+                ptr::read_and_zero(p.offset(i as int));
             }
         }
         unsafe { self.set_len(newlen); }
@@ -1648,7 +1648,7 @@ fn grow_fn(&mut self, n: uint, op: |uint| -> T) {
 
     #[inline]
     unsafe fn set_len(&mut self, new_len: uint) {
-        let repr: **mut Vec<()> = cast::transmute(self);
+        let repr: **mut Vec<()> = transmute(self);
         (**repr).fill = new_len * mem::nonzero_size_of::<T>();
     }
 }
@@ -1844,7 +1844,7 @@ fn insertion_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
             // `.offset(j)` is always in bounds.
 
             if i != j {
-                let tmp = ptr::read_ptr(read_ptr);
+                let tmp = ptr::read(read_ptr);
                 ptr::copy_memory(buf_v.offset(j + 1),
                                  &*buf_v.offset(j),
                                  (i - j) as uint);
@@ -2269,7 +2269,7 @@ fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
         assert!(start <= end);
         assert!(end <= self.len());
         unsafe {
-            cast::transmute(Slice {
+            transmute(Slice {
                     data: self.as_mut_ptr().offset(start as int) as *T,
                     len: (end - start)
                 })
@@ -2338,7 +2338,7 @@ fn mut_chunks(self, chunk_size: uint) -> MutChunks<'a, T> {
     fn mut_shift_ref(&mut self) -> Option<&'a mut T> {
         if self.len() == 0 { return None; }
         unsafe {
-            let s: &mut Slice<T> = cast::transmute(self);
+            let s: &mut Slice<T> = transmute(self);
             Some(cast::transmute_mut(&*raw::shift_ptr(s)))
         }
     }
@@ -2346,7 +2346,7 @@ fn mut_shift_ref(&mut self) -> Option<&'a mut T> {
     fn mut_pop_ref(&mut self) -> Option<&'a mut T> {
         if self.len() == 0 { return None; }
         unsafe {
-            let s: &mut Slice<T> = cast::transmute(self);
+            let s: &mut Slice<T> = transmute(self);
             Some(cast::transmute_mut(&*raw::pop_ptr(s)))
         }
     }
@@ -2357,7 +2357,7 @@ fn swap(self, a: uint, b: uint) {
             // them to their raw pointers to do the swap
             let pa: *mut T = &mut self[a];
             let pb: *mut T = &mut self[b];
-            ptr::swap_ptr(pa, pb);
+            ptr::swap(pa, pb);
         }
     }
 
@@ -2385,7 +2385,7 @@ fn move_from(self, mut src: ~[T], start: uint, end: uint) -> uint {
 
     #[inline]
     unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T {
-        cast::transmute((self.repr().data as *mut T).offset(index as int))
+        transmute((self.repr().data as *mut T).offset(index as int))
     }
 
     #[inline]
@@ -2484,7 +2484,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
 
 /// Unsafe operations
 pub mod raw {
-    use cast;
+    use cast::transmute;
     use ptr;
     use ptr::RawPtr;
     use vec::{with_capacity, MutableVector, OwnedVector};
@@ -2497,7 +2497,7 @@ pub mod raw {
     #[inline]
     pub unsafe fn buf_as_slice<T,U>(p: *T, len: uint, f: |v: &[T]| -> U)
                                -> U {
-        f(cast::transmute(Slice {
+        f(transmute(Slice {
             data: p,
             len: len
         }))
@@ -2514,7 +2514,7 @@ pub unsafe fn mut_buf_as_slice<T,
                                    len: uint,
                                    f: |v: &mut [T]| -> U)
                                    -> U {
-        f(cast::transmute(Slice {
+        f(transmute(Slice {
             data: p as *T,
             len: len
         }))
@@ -2698,12 +2698,12 @@ fn next(&mut self) -> Option<$elem> {
                             // purposefully don't use 'ptr.offset' because for
                             // vectors with 0-size elements this would return the
                             // same pointer.
-                            cast::transmute(self.ptr as uint + 1)
+                            transmute(self.ptr as uint + 1)
                         } else {
                             self.ptr.offset(1)
                         };
 
-                        Some(cast::transmute(old))
+                        Some(transmute(old))
                     }
                 }
             }
@@ -2726,11 +2726,11 @@ fn next_back(&mut self) -> Option<$elem> {
                     } else {
                         self.end = if mem::size_of::<T>() == 0 {
                             // See above for why 'ptr.offset' isn't used
-                            cast::transmute(self.end as uint - 1)
+                            transmute(self.end as uint - 1)
                         } else {
                             self.end.offset(-1)
                         };
-                        Some(cast::transmute(self.end))
+                        Some(transmute(self.end))
                     }
                 }
             }
@@ -2749,7 +2749,7 @@ fn indexable(&self) -> uint {
     fn idx(&self, index: uint) -> Option<&'a T> {
         unsafe {
             if index < self.indexable() {
-                cast::transmute(self.ptr.offset(index as int))
+                transmute(self.ptr.offset(index as int))
             } else {
                 None
             }
@@ -2895,7 +2895,7 @@ impl<T> Iterator<T> for MoveItems<T> {
     #[inline]
     fn next(&mut self) -> Option<T> {
         unsafe {
-            self.iter.next().map(|x| ptr::read_ptr(x))
+            self.iter.next().map(|x| ptr::read(x))
         }
     }
 
@@ -2909,7 +2909,7 @@ impl<T> DoubleEndedIterator<T> for MoveItems<T> {
     #[inline]
     fn next_back(&mut self) -> Option<T> {
         unsafe {
-            self.iter.next_back().map(|x| ptr::read_ptr(x))
+            self.iter.next_back().map(|x| ptr::read(x))
         }
     }
 }
index 25ba45021b3fa0364bb9571ec92aa5f87e556727..a450aab127bc43be17d36fc4971ef9543aa0ede2 100644 (file)
@@ -22,7 +22,7 @@
 use rt::global_heap::{malloc_raw, realloc_raw};
 use vec::{ImmutableVector, Items, MutableVector};
 use unstable::raw::Slice;
-use ptr::read_ptr;
+use ptr;
 use ptr::RawPtr;
 use libc::{free, c_void};
 
@@ -117,7 +117,7 @@ pub fn pop(&mut self) -> Option<T> {
         } else {
             unsafe {
                 self.len -= 1;
-                Some(read_ptr(self.as_slice().unsafe_ref(self.len())))
+                Some(ptr::read(self.as_slice().unsafe_ref(self.len())))
             }
         }
     }
@@ -147,7 +147,7 @@ pub fn truncate(&mut self, len: uint) {
             let mut i = len;
             // drop any extra elements
             while i < self.len {
-                read_ptr(self.as_slice().unsafe_ref(i));
+                ptr::read(self.as_slice().unsafe_ref(i));
                 i += 1;
             }
         }
@@ -188,7 +188,7 @@ impl<T> Drop for Vec<T> {
     fn drop(&mut self) {
         unsafe {
             for x in self.as_mut_slice().iter() {
-                read_ptr(x);
+                ptr::read(x);
             }
             free(self.ptr as *mut c_void)
         }
@@ -204,7 +204,7 @@ impl<T> Iterator<T> for MoveItems<T> {
     #[inline]
     fn next(&mut self) -> Option<T> {
         unsafe {
-            self.iter.next().map(|x| read_ptr(x))
+            self.iter.next().map(|x| ptr::read(x))
         }
     }
 
@@ -218,7 +218,7 @@ impl<T> DoubleEndedIterator<T> for MoveItems<T> {
     #[inline]
     fn next_back(&mut self) -> Option<T> {
         unsafe {
-            self.iter.next_back().map(|x| read_ptr(x))
+            self.iter.next_back().map(|x| ptr::read(x))
         }
     }
 }
index 5f3af86545462ddfd8bbfd413952a80ae825d73a..799f5b4d5320cb5777dfcc6c0edaf641c873db7f 100644 (file)
@@ -8,11 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::ptr;
-
 enum bottom { }
 
 fn main() {
-    let x = ptr::to_unsafe_ptr(&()) as *bottom;
+    let x = &() as *() as *bottom;
     match x { } //~ ERROR non-exhaustive patterns
 }
index fe1be6d06db83cce39d251bba32657a582da970c..4aedb4e96cfa32f845ed258724f8c3d77ff525bd 100644 (file)
 
 #[feature(managed_boxes)];
 
-use std::ptr;
-
 fn borrow(x: &int, f: |x: &int|) {
     f(x)
 }
 
 fn test1(x: @~int) {
     borrow(&*(*x).clone(), |p| {
-        let x_a = ptr::to_unsafe_ptr(&**x);
+        let x_a = &**x as *int;
         assert!((x_a as uint) != (p as *int as uint));
         assert_eq!(unsafe{*x_a}, *p);
     })
index e789727c4fe29e42eb656baff6de06fc0d41bd92..5cdda81c43604d436c5ff20dd0edf0205392b502 100644 (file)
@@ -14,8 +14,6 @@
 
 #[feature(managed_boxes)];
 
-use std::ptr;
-
 fn borrow(x: &int, f: |x: &int|) {
     let before = *x;
     f(x);
@@ -29,12 +27,11 @@ pub fn main() {
     let mut x = @F {f: ~3};
     borrow(x.f, |b_x| {
         assert_eq!(*b_x, 3);
-        assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
+        assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
         x = @F {f: ~4};
 
-        info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
-               ptr::to_unsafe_ptr(&(*b_x)) as uint);
+        info!("&*b_x = {:p}", &(*b_x));
         assert_eq!(*b_x, 3);
-        assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
+        assert!(&(*x.f) as *int != &(*b_x) as *int);
     })
 }
index 8ac654ffbddba2f52ef62b3a1b42079f510d50e6..3050d6fa0113005172c991a250f4ed45877a0240 100644 (file)
@@ -14,8 +14,6 @@
 
 #[feature(managed_boxes)];
 
-use std::ptr;
-
 fn borrow(x: &int, f: |x: &int|) {
     let before = *x;
     f(x);
@@ -29,12 +27,11 @@ pub fn main() {
     let mut x = ~@F{f: ~3};
     borrow(x.f, |b_x| {
         assert_eq!(*b_x, 3);
-        assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
+        assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
         *x = @F{f: ~4};
 
-        info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
-               ptr::to_unsafe_ptr(&(*b_x)) as uint);
+        info!("&*b_x = {:p}", &(*b_x));
         assert_eq!(*b_x, 3);
-        assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
+        assert!(&(*x.f) as *int != &(*b_x) as *int);
     })
 }
index 9ce8daa966cf671ba6e4728f1494621a5d77ec16..76dfbffc09c0667d61df085d755fe1291766e791 100644 (file)
@@ -14,8 +14,6 @@
 
 #[feature(managed_boxes)];
 
-use std::ptr;
-
 fn borrow(x: &int, f: |x: &int|) {
     let before = *x;
     f(x);
@@ -27,12 +25,11 @@ pub fn main() {
     let mut x = @3;
     borrow(x, |b_x| {
         assert_eq!(*b_x, 3);
-        assert_eq!(ptr::to_unsafe_ptr(&(*x)), ptr::to_unsafe_ptr(&(*b_x)));
+        assert_eq!(&(*x) as *int, &(*b_x) as *int);
         x = @22;
 
-        info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
-               ptr::to_unsafe_ptr(&(*b_x)) as uint);
+        info!("&*b_x = {:p}", &(*b_x));
         assert_eq!(*b_x, 3);
-        assert!(ptr::to_unsafe_ptr(&(*x)) != ptr::to_unsafe_ptr(&(*b_x)));
+        assert!(&(*x) as *int != &(*b_x) as *int);
     })
 }
index 065ef1dd42379af46dd88da9c13f02ee95b39689..00e59f5132db7eac0901b4ae8266fddc95a7f264 100644 (file)
@@ -14,8 +14,6 @@
 
 #[feature(managed_boxes)];
 
-use std::ptr;
-
 fn borrow(x: &int, f: |x: &int|) {
     let before = *x;
     f(x);
@@ -29,12 +27,11 @@ pub fn main() {
     let mut x = @F {f: ~3};
     borrow((*x).f, |b_x| {
         assert_eq!(*b_x, 3);
-        assert_eq!(ptr::to_unsafe_ptr(&(*x.f)), ptr::to_unsafe_ptr(&(*b_x)));
+        assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
         x = @F {f: ~4};
 
-        info!("ptr::to_unsafe_ptr(*b_x) = {:x}",
-               ptr::to_unsafe_ptr(&(*b_x)) as uint);
+        info!("&*b_x = {:p}", &(*b_x));
         assert_eq!(*b_x, 3);
-        assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
+        assert!(&(*x.f) as *int != &(*b_x) as *int);
     })
 }
diff --git a/src/test/run-pass/cap-clause-move.rs b/src/test/run-pass/cap-clause-move.rs
deleted file mode 100644 (file)
index 1fa7862..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::ptr;
-
-pub fn main() {
-    let x = ~3;
-    let y = ptr::to_unsafe_ptr(&(*x)) as uint;
-    let snd_move: proc() -> uint = proc() ptr::to_unsafe_ptr(&(*x)) as uint;
-    assert_eq!(snd_move(), y);
-
-    let x = ~4;
-    let y = ptr::to_unsafe_ptr(&(*x)) as uint;
-    let lam_move: proc() -> uint = proc() ptr::to_unsafe_ptr(&(*x)) as uint;
-    assert_eq!(lam_move(), y);
-}
index 6dce262dd9a888e7d6415a7c2e51ced421aa7cff..87363c0e55e869ae3dbb366a88aef639366d7184 100644 (file)
@@ -8,13 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::ptr;
-
 type Big = [u64, ..8];
 struct Pair<'a> { a: int, b: &'a Big }
 static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
 static y: &'static Pair<'static> = &Pair {a: 15, b: x};
 
 pub fn main() {
-    assert_eq!(ptr::to_unsafe_ptr(x), ptr::to_unsafe_ptr(y.b));
+    assert_eq!(x as *Big, y.b as *Big);
 }
index 3c8dd33ae9c356111c05e9979522c8f45c88b3f2..5763c61379865a88fef04703b0a2b908a1b2420a 100644 (file)
@@ -9,12 +9,10 @@
 // except according to those terms.
 
 use std::cast;
-use std::ptr;
 use std::mem;
 
 fn addr_of<T>(ptr: &T) -> uint {
-    let ptr = ptr::to_unsafe_ptr(ptr);
-    ptr as uint
+    ptr as *T as uint
 }
 
 fn is_aligned<T>(ptr: &T) -> bool {
index dc68777e033b0f91659bc9495c765aa023fa39cf..083d2e167a0757e54beb71f4cfa07b06831ee7ee 100644 (file)
@@ -10,9 +10,7 @@
 
 // Issue #2040
 
-use std::ptr;
-
 pub fn main() {
     let foo = 1;
-    assert_eq!(ptr::to_unsafe_ptr(&foo), ptr::to_unsafe_ptr(&foo));
+    assert_eq!(&foo as *int, &foo as *int);
 }
index 42f3089a87a193f43f083c017910900b27e2f60c..d9cf585ad6c0a293cf8835d67aa9695c7fa68f75 100644 (file)
@@ -25,7 +25,7 @@ pub fn main() {
 
 fn do_swap(test: &mut TestDescAndFn) {
     unsafe {
-        ptr::swap_ptr(test, test);
+        ptr::swap(test, test);
     }
 }
 
index 1ed0c23fd7a4ce4cb8c4e1ffb629922558bded70..944c498ede37fd1436aeec696d2bf0a173b6d1ff 100644 (file)
@@ -8,17 +8,16 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::ptr;
 use std::task;
 
 pub fn main() {
     let (p, ch) = Chan::<uint>::new();
 
     let x = ~1;
-    let x_in_parent = ptr::to_unsafe_ptr(&(*x)) as uint;
+    let x_in_parent = &(*x) as *int as uint;
 
     task::spawn(proc() {
-        let x_in_child = ptr::to_unsafe_ptr(&(*x)) as uint;
+        let x_in_child = &(*x) as *int as uint;
         ch.send(x_in_child);
     });
 
index 53836a6e17dfbb9e589a7dde3ef606db0fc7245d..9efa6c1b9646ad754a64b2cf2d831a3d43901367 100644 (file)
@@ -11,7 +11,6 @@
 #[feature(managed_boxes)];
 
 use std::cell::RefCell;
-use std::ptr;
 
 enum maybe_pointy {
     none,
@@ -24,7 +23,7 @@ struct Pointy {
 }
 
 fn make_uniq_closure<A:Send>(a: A) -> proc() -> uint {
-    let result: proc() -> uint = proc() ptr::to_unsafe_ptr(&a) as uint;
+    let result: proc() -> uint = proc() &a as *A as uint;
     result
 }