about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-13 15:17:21 -0800
committerbors <bors@rust-lang.org>2014-02-13 15:17:21 -0800
commit94d453e459107ed1c5d76f693686b29d31cdc58c (patch)
treeb586a7c785fa57253b3ba1bcaaee5ae1ea167411 /src/libstd
parentcfb87f10ec7d41d0e7f8c68fbb908fc195517d41 (diff)
parent640b22852f59e4505cedfd02c01cc343d5ec0d9e (diff)
auto merge of #12248 : alexcrichton/rust/rollup, r=alexcrichton
This passed `make check` locally, so hopefully it passes on bors!
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/any.rs26
-rw-r--r--src/libstd/ascii.rs13
-rw-r--r--src/libstd/c_str.rs47
-rw-r--r--src/libstd/cleanup.rs47
-rw-r--r--src/libstd/comm/select.rs120
-rw-r--r--src/libstd/comm/shared.rs18
-rw-r--r--src/libstd/comm/stream.rs18
-rw-r--r--src/libstd/hashmap.rs75
-rw-r--r--src/libstd/io/extensions.rs7
-rw-r--r--src/libstd/macros.rs14
-rw-r--r--src/libstd/ptr.rs43
-rw-r--r--src/libstd/reflect.rs7
-rw-r--r--src/libstd/repr.rs7
-rw-r--r--src/libstd/rt/global_heap.rs30
-rw-r--r--src/libstd/rt/local_heap.rs74
-rw-r--r--src/libstd/str.rs17
-rw-r--r--src/libstd/unit.rs7
-rw-r--r--src/libstd/unstable/intrinsics.rs4
-rw-r--r--src/libstd/unstable/lang.rs8
-rw-r--r--src/libstd/unstable/raw.rs13
-rw-r--r--src/libstd/vec.rs63
-rw-r--r--src/libstd/vec_ng.rs5
22 files changed, 366 insertions, 297 deletions
diff --git a/src/libstd/any.rs b/src/libstd/any.rs
index 24da59341cc..3f14db14882 100644
--- a/src/libstd/any.rs
+++ b/src/libstd/any.rs
@@ -21,6 +21,7 @@
 //! extension traits (`*Ext`) for the full details.
 
 use cast::transmute;
+use fmt;
 use option::{Option, Some, None};
 use result::{Result, Ok, Err};
 use to_str::ToStr;
@@ -158,6 +159,18 @@ impl<'a> ToStr for &'a Any {
     fn to_str(&self) -> ~str { ~"&Any" }
 }
 
+impl fmt::Show for ~Any {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad("~Any")
+    }
+}
+
+impl<'a> fmt::Show for &'a Any {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad("&Any")
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use prelude::*;
@@ -377,4 +390,17 @@ mod tests {
         assert!(a.move::<~Test>().is_err());
         assert!(b.move::<~uint>().is_err());
     }
+
+    #[test]
+    fn test_show() {
+        let a = ~8u as ~Any;
+        let b = ~Test as ~Any;
+        assert_eq!(format!("{}", a), ~"~Any");
+        assert_eq!(format!("{}", b), ~"~Any");
+
+        let a = &8u as &Any;
+        let b = &Test as &Any;
+        assert_eq!(format!("{}", a), ~"&Any");
+        assert_eq!(format!("{}", b), ~"&Any");
+    }
 }
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs
index 7965127007c..651d364dd1b 100644
--- a/src/libstd/ascii.rs
+++ b/src/libstd/ascii.rs
@@ -17,6 +17,7 @@ use str::StrSlice;
 use str::OwnedStr;
 use container::Container;
 use cast;
+use fmt;
 use iter::Iterator;
 use vec::{ImmutableVector, MutableVector, Vector};
 use to_bytes::IterBytes;
@@ -134,6 +135,12 @@ impl ToStr for Ascii {
     }
 }
 
+impl<'a> fmt::Show for Ascii {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        (self.chr as char).fmt(f)
+    }
+}
+
 /// Trait for converting into an ascii type.
 pub trait AsciiCast<T> {
     /// Convert to an ascii type, fail on non-ASCII input.
@@ -698,5 +705,9 @@ mod tests {
         assert_eq!(s, ~"t");
     }
 
-
+    #[test]
+    fn test_show() {
+        let c = Ascii { chr: 't' as u8 };
+        assert_eq!(format!("{}", c), ~"t");
+    }
 }
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs
index cc6cd7666d6..fe332a60efa 100644
--- a/src/libstd/c_str.rs
+++ b/src/libstd/c_str.rs
@@ -310,7 +310,7 @@ impl<'a> ToCStr for &'a [u8] {
         let buf = malloc_raw(self_len + 1);
 
         ptr::copy_memory(buf, self.as_ptr(), self_len);
-        *ptr::mut_offset(buf, self_len as int) = 0;
+        *buf.offset(self_len as int) = 0;
 
         CString::new(buf as *libc::c_char, true)
     }
@@ -368,7 +368,7 @@ impl<'a> Iterator<libc::c_char> for CChars<'a> {
         if ch == 0 {
             None
         } else {
-            self.ptr = unsafe { ptr::offset(self.ptr, 1) };
+            self.ptr = unsafe { self.ptr.offset(1) };
             Some(ch)
         }
     }
@@ -429,18 +429,18 @@ mod tests {
     fn test_str_to_c_str() {
         "".to_c_str().with_ref(|buf| {
             unsafe {
-                assert_eq!(*ptr::offset(buf, 0), 0);
+                assert_eq!(*buf.offset(0), 0);
             }
         });
 
         "hello".to_c_str().with_ref(|buf| {
             unsafe {
-                assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 5), 0);
+                assert_eq!(*buf.offset(0), 'h' as libc::c_char);
+                assert_eq!(*buf.offset(1), 'e' as libc::c_char);
+                assert_eq!(*buf.offset(2), 'l' as libc::c_char);
+                assert_eq!(*buf.offset(3), 'l' as libc::c_char);
+                assert_eq!(*buf.offset(4), 'o' as libc::c_char);
+                assert_eq!(*buf.offset(5), 0);
             }
         })
     }
@@ -450,28 +450,28 @@ mod tests {
         let b: &[u8] = [];
         b.to_c_str().with_ref(|buf| {
             unsafe {
-                assert_eq!(*ptr::offset(buf, 0), 0);
+                assert_eq!(*buf.offset(0), 0);
             }
         });
 
         let _ = bytes!("hello").to_c_str().with_ref(|buf| {
             unsafe {
-                assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 5), 0);
+                assert_eq!(*buf.offset(0), 'h' as libc::c_char);
+                assert_eq!(*buf.offset(1), 'e' as libc::c_char);
+                assert_eq!(*buf.offset(2), 'l' as libc::c_char);
+                assert_eq!(*buf.offset(3), 'l' as libc::c_char);
+                assert_eq!(*buf.offset(4), 'o' as libc::c_char);
+                assert_eq!(*buf.offset(5), 0);
             }
         });
 
         let _ = bytes!("foo", 0xff).to_c_str().with_ref(|buf| {
             unsafe {
-                assert_eq!(*ptr::offset(buf, 0), 'f' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 1), 'o' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 2), 'o' as libc::c_char);
-                assert_eq!(*ptr::offset(buf, 3), 0xff as i8);
-                assert_eq!(*ptr::offset(buf, 4), 0);
+                assert_eq!(*buf.offset(0), 'f' as libc::c_char);
+                assert_eq!(*buf.offset(1), 'o' as libc::c_char);
+                assert_eq!(*buf.offset(2), 'o' as libc::c_char);
+                assert_eq!(*buf.offset(3), 0xff as i8);
+                assert_eq!(*buf.offset(4), 0);
             }
         });
     }
@@ -634,7 +634,6 @@ mod bench {
     use extra::test::BenchHarness;
     use libc;
     use prelude::*;
-    use ptr;
 
     #[inline]
     fn check(s: &str, c_str: *libc::c_char) {
@@ -642,8 +641,8 @@ mod bench {
         for i in range(0, s.len()) {
             unsafe {
                 assert_eq!(
-                    *ptr::offset(s_buf, i as int) as libc::c_char,
-                    *ptr::offset(c_str, i as int));
+                    *s_buf.offset(i as int) as libc::c_char,
+                    *c_str.offset(i as int));
             }
         }
     }
diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs
index a43dca94970..dd43d8e2971 100644
--- a/src/libstd/cleanup.rs
+++ b/src/libstd/cleanup.rs
@@ -57,53 +57,6 @@ fn debug_mem() -> bool {
 }
 
 /// Destroys all managed memory (i.e. @ boxes) held by the current task.
-#[cfg(stage0)]
-pub unsafe fn annihilate() {
-    use rt::local_heap::local_free;
-
-    let mut n_total_boxes = 0u;
-
-    // Pass 1: Make all boxes immortal.
-    //
-    // In this pass, nothing gets freed, so it does not matter whether
-    // we read the next field before or after the callback.
-    each_live_alloc(true, |alloc| {
-        n_total_boxes += 1;
-        (*alloc).ref_count = RC_IMMORTAL;
-        true
-    });
-
-    // Pass 2: Drop all boxes.
-    //
-    // In this pass, unique-managed boxes may get freed, but not
-    // managed boxes, so we must read the `next` field *after* the
-    // callback, as the original value may have been freed.
-    each_live_alloc(false, |alloc| {
-        let tydesc = (*alloc).type_desc;
-        let data = &(*alloc).data as *();
-        ((*tydesc).drop_glue)(data as *i8);
-        true
-    });
-
-    // Pass 3: Free all boxes.
-    //
-    // In this pass, managed boxes may get freed (but not
-    // unique-managed boxes, though I think that none of those are
-    // left), so we must read the `next` field before, since it will
-    // not be valid after.
-    each_live_alloc(true, |alloc| {
-        local_free(alloc as *u8);
-        true
-    });
-
-    if debug_mem() {
-        // We do logging here w/o allocation.
-        debug!("total boxes annihilated: {}", n_total_boxes);
-    }
-}
-
-/// Destroys all managed memory (i.e. @ boxes) held by the current task.
-#[cfg(not(stage0))]
 pub unsafe fn annihilate() {
     use rt::local_heap::local_free;
 
diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs
index b6b35ccc357..e41fa60aa42 100644
--- a/src/libstd/comm/select.rs
+++ b/src/libstd/comm/select.rs
@@ -60,21 +60,17 @@ use uint;
 
 macro_rules! select {
     (
-        $name1:pat = $port1:ident.$meth1:ident() => $code1:expr,
-        $($name:pat = $port:ident.$meth:ident() => $code:expr),*
+        $($name:pat = $port:ident.$meth:ident() => $code:expr),+
     ) => ({
         use std::comm::Select;
         let sel = Select::new();
-        let mut $port1 = sel.handle(&$port1);
-        $( let mut $port = sel.handle(&$port); )*
+        $( let mut $port = sel.handle(&$port); )+
         unsafe {
-            $port1.add();
-            $( $port.add(); )*
+            $( $port.add(); )+
         }
         let ret = sel.wait();
-        if ret == $port1.id { let $name1 = $port1.$meth1(); $code1 }
-        $( else if ret == $port.id { let $name = $port.$meth(); $code } )*
-        else { unreachable!() }
+        $( if ret == $port.id() { let $name = $port.$meth(); $code } else )+
+        { unreachable!() }
     })
 }
 
@@ -94,7 +90,7 @@ pub struct Select {
 pub struct Handle<'port, T> {
     /// The ID of this handle, used to compare against the return value of
     /// `Select::wait()`
-    id: uint,
+    priv id: uint,
     priv selector: &'port Select,
     priv next: *mut Handle<'static, ()>,
     priv prev: *mut Handle<'static, ()>,
@@ -150,11 +146,16 @@ impl Select {
 
     /// Waits for an event on this port set. The returned valus is *not* and
     /// index, but rather an id. This id can be queried against any active
-    /// `Handle` structures (each one has a public `id` field). The handle with
+    /// `Handle` structures (each one has an `id` method). The handle with
     /// the matching `id` will have some sort of event available on it. The
     /// event could either be that data is available or the corresponding
     /// channel has been closed.
     pub fn wait(&self) -> uint {
+        self.wait2(false)
+    }
+
+    /// Helper method for skipping the preflight checks during testing
+    fn wait2(&self, do_preflight_checks: bool) -> uint {
         // Note that this is currently an inefficient implementation. We in
         // theory have knowledge about all ports in the set ahead of time, so
         // this method shouldn't really have to iterate over all of them yet
@@ -179,7 +180,7 @@ impl Select {
             let mut amt = 0;
             for p in self.iter() {
                 amt += 1;
-                if (*p).packet.can_recv() {
+                if do_preflight_checks && (*p).packet.can_recv() {
                     return (*p).id;
                 }
             }
@@ -242,6 +243,10 @@ impl Select {
 }
 
 impl<'port, T: Send> Handle<'port, T> {
+    /// Retrieve the id of this handle.
+    #[inline]
+    pub fn id(&self) -> uint { self.id }
+
     /// Receive a value on the underlying port. Has the same semantics as
     /// `Port.recv`
     pub fn recv(&mut self) -> T { self.port.recv() }
@@ -355,7 +360,7 @@ mod test {
         )
         drop(c2);
         select! (
-            bar = p2.recv_opt() => { assert_eq!(bar, None); },
+            bar = p2.recv_opt() => { assert_eq!(bar, None); }
         )
     })
 
@@ -507,7 +512,7 @@ mod test {
         let (p2, c2) = Chan::<()>::new();
         let (p, c) = Chan::new();
         spawn(proc() {
-            let mut s = Select::new();
+            let s = Select::new();
             let mut h1 = s.handle(&p1);
             let mut h2 = s.handle(&p2);
             unsafe { h2.add(); }
@@ -521,4 +526,91 @@ mod test {
         c2.send(());
         p.recv();
     })
+
+    test!(fn preflight1() {
+        let (p, c) = Chan::new();
+        c.send(());
+        select!(
+            () = p.recv() => {}
+        )
+    })
+
+    test!(fn preflight2() {
+        let (p, c) = Chan::new();
+        c.send(());
+        c.send(());
+        select!(
+            () = p.recv() => {}
+        )
+    })
+
+    test!(fn preflight3() {
+        let (p, c) = Chan::new();
+        drop(c.clone());
+        c.send(());
+        select!(
+            () = p.recv() => {}
+        )
+    })
+
+    test!(fn preflight4() {
+        let (p, c) = Chan::new();
+        c.send(());
+        let s = Select::new();
+        let mut h = s.handle(&p);
+        unsafe { h.add(); }
+        assert_eq!(s.wait2(false), h.id);
+    })
+
+    test!(fn preflight5() {
+        let (p, c) = Chan::new();
+        c.send(());
+        c.send(());
+        let s = Select::new();
+        let mut h = s.handle(&p);
+        unsafe { h.add(); }
+        assert_eq!(s.wait2(false), h.id);
+    })
+
+    test!(fn preflight6() {
+        let (p, c) = Chan::new();
+        drop(c.clone());
+        c.send(());
+        let s = Select::new();
+        let mut h = s.handle(&p);
+        unsafe { h.add(); }
+        assert_eq!(s.wait2(false), h.id);
+    })
+
+    test!(fn preflight7() {
+        let (p, c) = Chan::<()>::new();
+        drop(c);
+        let s = Select::new();
+        let mut h = s.handle(&p);
+        unsafe { h.add(); }
+        assert_eq!(s.wait2(false), h.id);
+    })
+
+    test!(fn preflight8() {
+        let (p, c) = Chan::new();
+        c.send(());
+        drop(c);
+        p.recv();
+        let s = Select::new();
+        let mut h = s.handle(&p);
+        unsafe { h.add(); }
+        assert_eq!(s.wait2(false), h.id);
+    })
+
+    test!(fn preflight9() {
+        let (p, c) = Chan::new();
+        drop(c.clone());
+        c.send(());
+        drop(c);
+        p.recv();
+        let s = Select::new();
+        let mut h = s.handle(&p);
+        unsafe { h.add(); }
+        assert_eq!(s.wait2(false), h.id);
+    })
 }
diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs
index 30e061bb7b9..77bf2d7a68d 100644
--- a/src/libstd/comm/shared.rs
+++ b/src/libstd/comm/shared.rs
@@ -398,6 +398,17 @@ impl<T: Send> Packet<T> {
         cnt == DISCONNECTED || cnt - self.steals > 0
     }
 
+    // increment the count on the channel (used for selection)
+    fn bump(&mut self, amt: int) -> int {
+        match self.cnt.fetch_add(amt, atomics::SeqCst) {
+            DISCONNECTED => {
+                self.cnt.store(DISCONNECTED, atomics::SeqCst);
+                DISCONNECTED
+            }
+            n => n
+        }
+    }
+
     // Inserts the blocked task for selection on this port, returning it back if
     // the port already has data on it.
     //
@@ -408,8 +419,8 @@ impl<T: Send> Packet<T> {
         match self.decrement(task) {
             Ok(()) => Ok(()),
             Err(task) => {
-                let prev = self.cnt.fetch_add(1, atomics::SeqCst);
-                assert!(prev >= 0);
+                let prev = self.bump(1);
+                assert!(prev == DISCONNECTED || prev >= 0);
                 return Err(task);
             }
         }
@@ -440,11 +451,10 @@ impl<T: Send> Packet<T> {
             let cnt = self.cnt.load(atomics::SeqCst);
             if cnt < 0 && cnt != DISCONNECTED {-cnt} else {0}
         };
-        let prev = self.cnt.fetch_add(steals + 1, atomics::SeqCst);
+        let prev = self.bump(steals + 1);
 
         if prev == DISCONNECTED {
             assert_eq!(self.to_wake.load(atomics::SeqCst), 0);
-            self.cnt.store(DISCONNECTED, atomics::SeqCst);
             true
         } else {
             let cur = prev + steals + 1;
diff --git a/src/libstd/comm/stream.rs b/src/libstd/comm/stream.rs
index 0e249a55f87..9c972a3771c 100644
--- a/src/libstd/comm/stream.rs
+++ b/src/libstd/comm/stream.rs
@@ -333,6 +333,17 @@ impl<T: Send> Packet<T> {
         }
     }
 
+    // increment the count on the channel (used for selection)
+    fn bump(&mut self, amt: int) -> int {
+        match self.cnt.fetch_add(amt, atomics::SeqCst) {
+            DISCONNECTED => {
+                self.cnt.store(DISCONNECTED, atomics::SeqCst);
+                DISCONNECTED
+            }
+            n => n
+        }
+    }
+
     // Attempts to start selecting on this port. Like a oneshot, this can fail
     // immediately because of an upgrade.
     pub fn start_selection(&mut self, task: BlockedTask) -> SelectionResult<T> {
@@ -351,8 +362,8 @@ impl<T: Send> Packet<T> {
                 };
                 // Undo our decrement above, and we should be guaranteed that the
                 // previous value is positive because we're not going to sleep
-                let prev = self.cnt.fetch_add(1, atomics::SeqCst);
-                assert!(prev >= 0);
+                let prev = self.bump(1);
+                assert!(prev == DISCONNECTED || prev >= 0);
                 return ret;
             }
         }
@@ -384,13 +395,12 @@ impl<T: Send> Packet<T> {
         // and in the stream case we can have at most one steal, so just assume
         // that we had one steal.
         let steals = 1;
-        let prev = self.cnt.fetch_add(steals + 1, atomics::SeqCst);
+        let prev = self.bump(steals + 1);
 
         // If we were previously disconnected, then we know for sure that there
         // is no task in to_wake, so just keep going
         let has_data = if prev == DISCONNECTED {
             assert_eq!(self.to_wake.load(atomics::SeqCst), 0);
-            self.cnt.store(DISCONNECTED, atomics::SeqCst);
             true // there is data, that data is that we're disconnected
         } else {
             let cur = prev + steals + 1;
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 953cc66a2cb..c49294a095f 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -56,6 +56,7 @@ use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
 use clone::Clone;
 use cmp::{Eq, Equiv};
 use default::Default;
+#[cfg(not(stage0))] use fmt;
 use hash::Hash;
 use iter;
 use iter::{Iterator, FromIterator, Extendable};
@@ -65,6 +66,7 @@ use num;
 use option::{None, Option, Some};
 use rand::Rng;
 use rand;
+#[cfg(not(stage0))] use result::{Ok, Err};
 use vec::{ImmutableVector, MutableVector, OwnedVector, Items, MutItems};
 use vec_ng;
 use vec_ng::Vec;
@@ -595,6 +597,23 @@ impl<K:Hash + Eq + Clone,V:Clone> Clone for HashMap<K,V> {
     }
 }
 
+#[cfg(not(stage0))]
+impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for HashMap<A, B> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if_ok!(write!(f.buf, r"\{"))
+        let mut first = true;
+        for (key, value) in self.iter() {
+            if first {
+                first = false;
+            } else {
+                if_ok!(write!(f.buf, ", "));
+            }
+            if_ok!(write!(f.buf, "{}: {}", *key, *value));
+        }
+        write!(f.buf, r"\}")
+    }
+}
+
 /// HashMap iterator
 #[deriving(Clone)]
 pub struct Entries<'a, K, V> {
@@ -857,6 +876,23 @@ impl<T:Hash + Eq + Clone> Clone for HashSet<T> {
     }
 }
 
+#[cfg(not(stage0))]
+impl<A: fmt::Show + Hash + Eq> fmt::Show for HashSet<A> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if_ok!(write!(f.buf, r"\{"))
+        let mut first = true;
+        for x in self.iter() {
+            if first {
+                first = false;
+            } else {
+                if_ok!(write!(f.buf, ", "));
+            }
+            if_ok!(write!(f.buf, "{}", *x));
+        }
+        write!(f.buf, r"\}")
+    }
+}
+
 impl<K: Eq + Hash> FromIterator<K> for HashSet<K> {
     fn from_iterator<T: Iterator<K>>(iter: &mut T) -> HashSet<K> {
         let (lower, _) = iter.size_hint();
@@ -890,6 +926,7 @@ pub type SetAlgebraItems<'a, T> =
 mod test_map {
     use prelude::*;
     use super::*;
+    use fmt;
 
     #[test]
     fn test_create_capacity_zero() {
@@ -1121,6 +1158,30 @@ mod test_map {
             assert_eq!(map.find(&k), Some(&v));
         }
     }
+
+    struct ShowableStruct {
+        value: int,
+    }
+
+    impl fmt::Show for ShowableStruct {
+        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+            write!(f.buf, r"s{}", self.value)
+        }
+    }
+
+    #[test]
+    fn test_show() {
+        let mut table: HashMap<int, ShowableStruct> = HashMap::new();
+        let empty: HashMap<int, ShowableStruct> = HashMap::new();
+
+        table.insert(3, ShowableStruct { value: 4 });
+        table.insert(1, ShowableStruct { value: 2 });
+
+        let table_str = format!("{}", table);
+
+        assert!(table_str == ~"{1: s2, 3: s4}" || table_str == ~"{3: s4, 1: s2}");
+        assert_eq!(format!("{}", empty), ~"{}");
+    }
 }
 
 #[cfg(test)]
@@ -1346,4 +1407,18 @@ mod test_set {
 
         assert_eq!(s1, s2);
     }
+
+    #[test]
+    fn test_show() {
+        let mut set: HashSet<int> = HashSet::new();
+        let empty: HashSet<int> = HashSet::new();
+
+        set.insert(1);
+        set.insert(2);
+
+        let set_str = format!("{}", set);
+
+        assert!(set_str == ~"{1, 2}" || set_str == ~"{2, 1}");
+        assert_eq!(format!("{}", empty), ~"{}");
+    }
 }
diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs
index 240f4c65501..da4697d0e48 100644
--- a/src/libstd/io/extensions.rs
+++ b/src/libstd/io/extensions.rs
@@ -18,6 +18,7 @@ use iter::Iterator;
 use option::Option;
 use io::Reader;
 use vec::{OwnedVector, ImmutableVector};
+use ptr::RawPtr;
 
 /// An iterator that reads a single byte on each iteration,
 /// until `.read_byte()` returns `None`.
@@ -104,7 +105,7 @@ pub fn u64_from_be_bytes(data: &[u8],
                          start: uint,
                          size: uint)
                       -> u64 {
-    use ptr::{copy_nonoverlapping_memory, offset, mut_offset};
+    use ptr::{copy_nonoverlapping_memory};
     use mem::from_be64;
     use vec::MutableVector;
 
@@ -116,9 +117,9 @@ pub fn u64_from_be_bytes(data: &[u8],
 
     let mut buf = [0u8, ..8];
     unsafe {
-        let ptr = offset(data.as_ptr(), start as int);
+        let ptr = data.as_ptr().offset(start as int);
         let out = buf.as_mut_ptr();
-        copy_nonoverlapping_memory(mut_offset(out, (8 - size) as int), ptr, size);
+        copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size);
         from_be64(*(out as *i64)) as u64
     }
 }
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index be1fdc4594d..14ae7c9900c 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -145,16 +145,18 @@ macro_rules! format(
 
 #[macro_export]
 macro_rules! write(
-    ($dst:expr, $($arg:tt)*) => (
-        format_args!(|args| { ::std::fmt::write($dst, args) }, $($arg)*)
-    )
+    ($dst:expr, $($arg:tt)*) => ({
+        let dst: &mut ::std::io::Writer = $dst;
+        format_args!(|args| { ::std::fmt::write(dst, args) }, $($arg)*)
+    })
 )
 
 #[macro_export]
 macro_rules! writeln(
-    ($dst:expr, $($arg:tt)*) => (
-        format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
-    )
+    ($dst:expr, $($arg:tt)*) => ({
+        let dst: &mut ::std::io::Writer = $dst;
+        format_args!(|args| { ::std::fmt::writeln(dst, args) }, $($arg)*)
+    })
 )
 
 #[macro_export]
diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs
index 80439d69899..2ba6f7d4fd6 100644
--- a/src/libstd/ptr.rs
+++ b/src/libstd/ptr.rs
@@ -21,23 +21,6 @@ use unstable::intrinsics;
 
 #[cfg(not(test))] use cmp::{Eq, Ord};
 
-/// Calculate the offset from a pointer.
-/// The `count` argument is in units of T; e.g. a `count` of 3
-/// represents a pointer offset of `3 * sizeof::<T>()` bytes.
-#[inline]
-pub unsafe fn offset<T>(ptr: *T, count: int) -> *T {
-    intrinsics::offset(ptr, count)
-}
-
-/// Calculate the offset from a mut pointer. The count *must* be in bounds or
-/// otherwise the loads of this address are undefined.
-/// The `count` argument is in units of T; e.g. a `count` of 3
-/// represents a pointer offset of `3 * sizeof::<T>()` bytes.
-#[inline]
-pub unsafe fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
-    intrinsics::offset(ptr as *T, count) as *mut T
-}
-
 /// Return the offset of the first null pointer in `buf`.
 #[inline]
 pub unsafe fn buf_len<T>(buf: **T) -> uint {
@@ -63,7 +46,7 @@ impl<T> Clone for *mut T {
 pub unsafe fn position<T>(buf: *T, f: |&T| -> bool) -> uint {
     let mut i = 0;
     loop {
-        if f(&(*offset(buf, i as int))) { return i; }
+        if f(&(*buf.offset(i as int))) { return i; }
         else { i += 1; }
     }
 }
@@ -76,14 +59,6 @@ pub fn null<T>() -> *T { 0 as *T }
 #[inline]
 pub fn mut_null<T>() -> *mut T { 0 as *mut T }
 
-/// Returns true if the pointer is equal to the null pointer.
-#[inline]
-pub fn is_null<T,P:RawPtr<T>>(ptr: P) -> bool { ptr.is_null() }
-
-/// Returns true if the pointer is not equal to the null pointer.
-#[inline]
-pub fn is_not_null<T,P:RawPtr<T>>(ptr: P) -> bool { ptr.is_not_null() }
-
 /**
  * Copies data from one location to another.
  *
@@ -206,7 +181,7 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) {
     }
     //let start_ptr = *arr;
     for e in range(0, len) {
-        let n = offset(arr, e as int);
+        let n = arr.offset(e as int);
         cb(*n);
     }
     debug!("array_each_with_len: after iterate");
@@ -278,7 +253,7 @@ impl<T> RawPtr<T> for *T {
     /// 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 { offset(self, count) }
+    unsafe fn offset(self, count: int) -> *T { intrinsics::offset(self, count) }
 }
 
 /// Extension methods for mutable pointers
@@ -323,7 +298,7 @@ impl<T> RawPtr<T> for *mut T {
     /// 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 { mut_offset(self, count) }
+    unsafe fn offset(self, count: int) -> *mut T { intrinsics::offset(self as *T, count) as *mut T }
 }
 
 // Equality for pointers
@@ -478,14 +453,14 @@ pub mod ptr_tests {
             let v0 = ~[32000u16, 32001u16, 32002u16];
             let mut v1 = ~[0u16, 0u16, 0u16];
 
-            copy_memory(mut_offset(v1.as_mut_ptr(), 1),
-                        offset(v0.as_ptr(), 1), 1);
+            copy_memory(v1.as_mut_ptr().offset(1),
+                        v0.as_ptr().offset(1), 1);
             assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
             copy_memory(v1.as_mut_ptr(),
-                        offset(v0.as_ptr(), 2), 1);
+                        v0.as_ptr().offset(2), 1);
             assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
                      v1[2] == 0u16));
-            copy_memory(mut_offset(v1.as_mut_ptr(), 2),
+            copy_memory(v1.as_mut_ptr().offset(2),
                         v0.as_ptr(), 1u);
             assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
                      v1[2] == 32000u16));
@@ -525,7 +500,7 @@ pub mod ptr_tests {
         assert!(p.is_null());
         assert!(!p.is_not_null());
 
-        let q = unsafe { offset(p, 1) };
+        let q = unsafe { p.offset(1) };
         assert!(!q.is_null());
         assert!(q.is_not_null());
 
diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs
index 1c22408592a..f88da60ae9b 100644
--- a/src/libstd/reflect.rs
+++ b/src/libstd/reflect.rs
@@ -441,11 +441,4 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
         self.align_to::<&'static u8>();
         true
     }
-
-    // NOTE Remove after next snapshot.
-    #[cfg(stage0)]
-    fn visit_type(&mut self) -> bool {
-        if ! self.inner.visit_type() { return false; }
-        true
-    }
 }
diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs
index 4ced74a92b7..58c00177b90 100644
--- a/src/libstd/repr.rs
+++ b/src/libstd/repr.rs
@@ -23,6 +23,7 @@ use io;
 use iter::Iterator;
 use option::{Some, None, Option};
 use ptr;
+use ptr::RawPtr;
 use reflect;
 use reflect::{MovePtr, align};
 use result::{Ok, Err};
@@ -221,7 +222,7 @@ impl<'a> ReprVisitor<'a> {
                 if_ok!(self, self.writer.write(", ".as_bytes()));
             }
             self.visit_ptr_inner(p as *u8, inner);
-            p = align(unsafe { ptr::offset(p, sz as int) as uint }, al) as *u8;
+            p = align(unsafe { p.offset(sz as int) as uint }, al) as *u8;
             left -= dec;
         }
         if_ok!(self, self.writer.write([']' as u8]));
@@ -601,10 +602,6 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
 
     fn visit_param(&mut self, _i: uint) -> bool { true }
     fn visit_self(&mut self) -> bool { true }
-
-    // NOTE Remove after next snapshot.
-    #[cfg(stage0)]
-    fn visit_type(&mut self) -> bool { true }
 }
 
 pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> {
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs
index 2f553585f38..4bce16706ee 100644
--- a/src/libstd/rt/global_heap.rs
+++ b/src/libstd/rt/global_heap.rs
@@ -10,8 +10,6 @@
 
 use libc::{c_void, size_t, free, malloc, realloc};
 use ptr::{RawPtr, mut_null};
-#[cfg(stage0)]
-use unstable::intrinsics::TyDesc;
 use unstable::intrinsics::abort;
 use unstable::raw;
 use mem::size_of;
@@ -75,15 +73,7 @@ pub unsafe fn exchange_malloc(size: uint) -> *u8 {
 }
 
 // FIXME: #7496
-#[cfg(not(test), stage0)]
-#[lang="closure_exchange_malloc"]
-#[inline]
-pub unsafe fn closure_exchange_malloc_(td: *u8, size: uint) -> *u8 {
-    closure_exchange_malloc(td, size)
-}
-
-// FIXME: #7496
-#[cfg(not(test), not(stage0))]
+#[cfg(not(test))]
 #[lang="closure_exchange_malloc"]
 #[inline]
 pub unsafe fn closure_exchange_malloc_(drop_glue: fn(*mut u8), size: uint, align: uint) -> *u8 {
@@ -91,24 +81,6 @@ pub unsafe fn closure_exchange_malloc_(drop_glue: fn(*mut u8), size: uint, align
 }
 
 #[inline]
-#[cfg(stage0)]
-pub unsafe fn closure_exchange_malloc(td: *u8, size: uint) -> *u8 {
-    let td = td as *TyDesc;
-    let size = size;
-
-    assert!(td.is_not_null());
-
-    let total_size = get_box_size(size, (*td).align);
-    let p = malloc_raw(total_size);
-
-    let alloc = p as *mut raw::Box<()>;
-    (*alloc).type_desc = td;
-
-    alloc as *u8
-}
-
-#[inline]
-#[cfg(not(stage0))]
 pub unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uint) -> *u8 {
     let total_size = get_box_size(size, align);
     let p = malloc_raw(total_size);
diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs
index 3bee9e48b60..023f712d3a0 100644
--- a/src/libstd/rt/local_heap.rs
+++ b/src/libstd/rt/local_heap.rs
@@ -21,8 +21,6 @@ use rt::env;
 use rt::global_heap;
 use rt::local::Local;
 use rt::task::Task;
-#[cfg(stage0)]
-use unstable::intrinsics::TyDesc;
 use unstable::raw;
 use vec::ImmutableVector;
 
@@ -61,29 +59,6 @@ impl LocalHeap {
     }
 
     #[inline]
-    #[cfg(stage0)]
-    pub fn alloc(&mut self, td: *TyDesc, size: uint) -> *mut Box {
-        let total_size = global_heap::get_box_size(size, unsafe { (*td).align });
-        let alloc = self.memory_region.malloc(total_size);
-        {
-            // Make sure that we can't use `mybox` outside of this scope
-            let mybox: &mut Box = unsafe { cast::transmute(alloc) };
-            // Clear out this box, and move it to the front of the live
-            // allocations list
-            mybox.type_desc = td;
-            mybox.ref_count = 1;
-            mybox.prev = ptr::mut_null();
-            mybox.next = self.live_allocs;
-            if !self.live_allocs.is_null() {
-                unsafe { (*self.live_allocs).prev = alloc; }
-            }
-            self.live_allocs = alloc;
-        }
-        return alloc;
-    }
-
-    #[inline]
-    #[cfg(not(stage0))]
     pub fn alloc(&mut self, drop_glue: fn(*mut u8), size: uint, align: uint) -> *mut Box {
         let total_size = global_heap::get_box_size(size, align);
         let alloc = self.memory_region.malloc(total_size);
@@ -126,41 +101,6 @@ impl LocalHeap {
     }
 
     #[inline]
-    #[cfg(stage0)]
-    pub fn free(&mut self, alloc: *mut Box) {
-        {
-            // Make sure that we can't use `mybox` outside of this scope
-            let mybox: &mut Box = unsafe { cast::transmute(alloc) };
-            assert!(!mybox.type_desc.is_null());
-
-            // Unlink it from the linked list
-            if !mybox.prev.is_null() {
-                unsafe { (*mybox.prev).next = mybox.next; }
-            }
-            if !mybox.next.is_null() {
-                unsafe { (*mybox.next).prev = mybox.prev; }
-            }
-            if self.live_allocs == alloc {
-                self.live_allocs = mybox.next;
-            }
-
-            // Destroy the box memory-wise
-            if self.poison_on_free {
-                unsafe {
-                    let ptr: *mut u8 = cast::transmute(&mybox.data);
-                    ptr::set_memory(ptr, 0xab, (*mybox.type_desc).size);
-                }
-            }
-            mybox.prev = ptr::mut_null();
-            mybox.next = ptr::mut_null();
-            mybox.type_desc = ptr::null();
-        }
-
-        self.memory_region.free(alloc);
-    }
-
-    #[inline]
-    #[cfg(not(stage0))]
     pub fn free(&mut self, alloc: *mut Box) {
         {
             // Make sure that we can't use `mybox` outside of this scope
@@ -339,20 +279,6 @@ impl Drop for MemoryRegion {
 }
 
 #[inline]
-#[cfg(stage0)]
-pub unsafe fn local_malloc(td: *u8, size: uint) -> *u8 {
-    // FIXME: Unsafe borrow for speed. Lame.
-    let task: Option<*mut Task> = Local::try_unsafe_borrow();
-    match task {
-        Some(task) => {
-            (*task).heap.alloc(td as *TyDesc, size) as *u8
-        }
-        None => rtabort!("local malloc outside of task")
-    }
-}
-
-#[inline]
-#[cfg(not(stage0))]
 pub unsafe fn local_malloc(drop_glue: fn(*mut u8), size: uint, align: uint) -> *u8 {
     // FIXME: Unsafe borrow for speed. Lame.
     let task: Option<*mut Task> = Local::try_unsafe_borrow();
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index bc5991c6eeb..0d263d94ccf 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -1242,7 +1242,7 @@ pub mod raw {
         let mut i = 0;
         while *curr != 0 {
             i += 1;
-            curr = ptr::offset(buf, i);
+            curr = buf.offset(i);
         }
         from_buf_len(buf as *u8, i as uint)
     }
@@ -1272,7 +1272,7 @@ pub mod raw {
         let mut len = 0u;
         while *curr != 0u8 {
             len += 1u;
-            curr = ptr::offset(s, len as int);
+            curr = s.offset(len as int);
         }
         let v = Slice { data: s, len: len };
         assert!(is_utf8(::cast::transmute(v)));
@@ -2921,7 +2921,6 @@ impl Default for ~str {
 mod tests {
     use iter::AdditiveIterator;
     use prelude::*;
-    use ptr;
     use str::*;
 
     #[test]
@@ -3549,11 +3548,11 @@ mod tests {
     fn test_as_ptr() {
         let buf = "hello".as_ptr();
         unsafe {
-            assert_eq!(*ptr::offset(buf, 0), 'h' as u8);
-            assert_eq!(*ptr::offset(buf, 1), 'e' as u8);
-            assert_eq!(*ptr::offset(buf, 2), 'l' as u8);
-            assert_eq!(*ptr::offset(buf, 3), 'l' as u8);
-            assert_eq!(*ptr::offset(buf, 4), 'o' as u8);
+            assert_eq!(*buf.offset(0), 'h' as u8);
+            assert_eq!(*buf.offset(1), 'e' as u8);
+            assert_eq!(*buf.offset(2), 'l' as u8);
+            assert_eq!(*buf.offset(3), 'l' as u8);
+            assert_eq!(*buf.offset(4), 'o' as u8);
         }
     }
 
@@ -4164,6 +4163,7 @@ mod tests {
         assert_eq!(s.len(), 5);
         assert_eq!(s.as_slice(), "abcde");
         assert_eq!(s.to_str(), ~"abcde");
+        assert_eq!(format!("{}", s), ~"abcde");
         assert!(s.lt(&Owned(~"bcdef")));
         assert_eq!(Slice(""), Default::default());
 
@@ -4171,6 +4171,7 @@ mod tests {
         assert_eq!(o.len(), 5);
         assert_eq!(o.as_slice(), "abcde");
         assert_eq!(o.to_str(), ~"abcde");
+        assert_eq!(format!("{}", o), ~"abcde");
         assert!(o.lt(&Slice("bcdef")));
         assert_eq!(Owned(~""), Default::default());
 
diff --git a/src/libstd/unit.rs b/src/libstd/unit.rs
index 3aa3e020500..b23dafbca69 100644
--- a/src/libstd/unit.rs
+++ b/src/libstd/unit.rs
@@ -14,6 +14,7 @@
 use default::Default;
 #[cfg(not(test))]
 use cmp::{Eq, Equal, Ord, Ordering, TotalEq, TotalOrd};
+use fmt;
 
 #[cfg(not(test))]
 impl Eq for () {
@@ -46,3 +47,9 @@ impl Default for () {
     #[inline]
     fn default() -> () { () }
 }
+
+impl fmt::Show for () {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad("()")
+    }
+}
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs
index b9e9c9d5a43..c983d82563c 100644
--- a/src/libstd/unstable/intrinsics.rs
+++ b/src/libstd/unstable/intrinsics.rs
@@ -160,10 +160,6 @@ pub trait TyVisitor {
     fn visit_trait(&mut self, name: &str) -> bool;
     fn visit_param(&mut self, i: uint) -> bool;
     fn visit_self(&mut self) -> bool;
-
-    // NOTE Remove after next snapshot.
-    #[cfg(stage0)]
-    fn visit_type(&mut self) -> bool;
 }
 
 extern "rust-intrinsic" {
diff --git a/src/libstd/unstable/lang.rs b/src/libstd/unstable/lang.rs
index a85f26720bf..4648f149a9f 100644
--- a/src/libstd/unstable/lang.rs
+++ b/src/libstd/unstable/lang.rs
@@ -27,14 +27,6 @@ pub fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! {
 }
 
 #[lang="malloc"]
-#[cfg(stage0)]
-#[inline]
-pub unsafe fn local_malloc(td: *u8, size: uint) -> *u8 {
-    ::rt::local_heap::local_malloc(td, size)
-}
-
-#[lang="malloc"]
-#[cfg(not(stage0))]
 #[inline]
 pub unsafe fn local_malloc(drop_glue: fn(*mut u8), size: uint, align: uint) -> *u8 {
     ::rt::local_heap::local_malloc(drop_glue, size, align)
diff --git a/src/libstd/unstable/raw.rs b/src/libstd/unstable/raw.rs
index 98dde95d3b7..87547997798 100644
--- a/src/libstd/unstable/raw.rs
+++ b/src/libstd/unstable/raw.rs
@@ -9,21 +9,8 @@
 // except according to those terms.
 
 use cast;
-#[cfg(stage0)]
-use unstable::intrinsics::TyDesc;
 
 /// The representation of a Rust managed box
-#[cfg(stage0)]
-pub struct Box<T> {
-    ref_count: uint,
-    type_desc: *TyDesc,
-    prev: *mut Box<T>,
-    next: *mut Box<T>,
-    data: T
-}
-
-/// The representation of a Rust managed box
-#[cfg(not(stage0))]
 pub struct Box<T> {
     ref_count: uint,
     drop_glue: fn(ptr: *mut u8),
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 2acafecf957..c67b19933d3 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -108,6 +108,7 @@ use container::{Container, Mutable};
 use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
 use cmp;
 use default::Default;
+#[cfg(not(stage0))] use fmt;
 use iter::*;
 use num::{Integer, CheckedAdd, Saturating, checked_next_power_of_two};
 use option::{None, Option, Some};
@@ -115,6 +116,7 @@ use ptr::to_unsafe_ptr;
 use ptr;
 use ptr::RawPtr;
 use rt::global_heap::{malloc_raw, realloc_raw, exchange_free};
+#[cfg(not(stage0))] use result::{Ok, Err};
 use mem;
 use mem::size_of;
 use kinds::marker;
@@ -137,7 +139,7 @@ pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> ~[T] {
             &mut i, (),
             |i, ()| while *i < n_elts {
                 mem::move_val_init(
-                    &mut(*ptr::mut_offset(p, *i as int)),
+                    &mut(*p.offset(*i as int)),
                     op(*i));
                 *i += 1u;
             },
@@ -165,7 +167,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
             &mut i, (),
             |i, ()| while *i < n_elts {
                 mem::move_val_init(
-                    &mut(*ptr::mut_offset(p, *i as int)),
+                    &mut(*p.offset(*i as int)),
                     t.clone());
                 *i += 1u;
             },
@@ -1495,7 +1497,7 @@ impl<T> OwnedVector<T> for ~[T] {
             let fill = (**repr).fill;
             (**repr).fill += mem::nonzero_size_of::<T>();
             let p = to_unsafe_ptr(&((**repr).data));
-            let p = ptr::offset(p, fill as int) as *mut T;
+            let p = p.offset(fill as int) as *mut T;
             mem::move_val_init(&mut(*p), t);
         }
     }
@@ -1509,7 +1511,7 @@ impl<T> OwnedVector<T> for ~[T] {
         unsafe { // Note: infallible.
             let self_p = self.as_mut_ptr();
             let rhs_p = rhs.as_ptr();
-            ptr::copy_memory(ptr::mut_offset(self_p, self_len as int), rhs_p, rhs_len);
+            ptr::copy_memory(self_p.offset(self_len as int), rhs_p, rhs_len);
             self.set_len(new_len);
             rhs.set_len(0);
         }
@@ -1796,11 +1798,11 @@ impl<T:Eq> OwnedEqVector<T> for ~[T] {
             let mut w = 1;
 
             while r < ln {
-                let p_r = ptr::mut_offset(p, r as int);
-                let p_wm1 = ptr::mut_offset(p, (w - 1) as int);
+                let p_r = p.offset(r as int);
+                let p_wm1 = p.offset((w - 1) as int);
                 if *p_r != *p_wm1 {
                     if r != w {
-                        let p_w = ptr::mut_offset(p_wm1, 1);
+                        let p_w = p_wm1.offset(1);
                         mem::swap(&mut *p_r, &mut *p_w);
                     }
                     w += 1;
@@ -2383,7 +2385,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
 
     #[inline]
     unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T {
-        cast::transmute(ptr::mut_offset(self.repr().data as *mut T, index as int))
+        cast::transmute((self.repr().data as *mut T).offset(index as int))
     }
 
     #[inline]
@@ -2484,6 +2486,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
 pub mod raw {
     use cast;
     use ptr;
+    use ptr::RawPtr;
     use vec::{with_capacity, MutableVector, OwnedVector};
     use unstable::raw::Slice;
 
@@ -2542,7 +2545,7 @@ pub mod raw {
     pub unsafe fn shift_ptr<T>(slice: &mut Slice<T>) -> *T {
         if slice.len == 0 { fail!("shift on empty slice"); }
         let head: *T = slice.data;
-        slice.data = ptr::offset(slice.data, 1);
+        slice.data = slice.data.offset(1);
         slice.len -= 1;
         head
     }
@@ -2554,7 +2557,7 @@ pub mod raw {
      */
     pub unsafe fn pop_ptr<T>(slice: &mut Slice<T>) -> *T {
         if slice.len == 0 { fail!("pop on empty slice"); }
-        let tail: *T = ptr::offset(slice.data, (slice.len - 1) as int);
+        let tail: *T = slice.data.offset((slice.len - 1) as int);
         slice.len -= 1;
         tail
     }
@@ -2640,6 +2643,30 @@ impl<A: DeepClone> DeepClone for ~[A] {
     }
 }
 
+#[cfg(not(stage0))]
+impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        if_ok!(write!(f.buf, "["));
+        let mut is_first = true;
+        for x in self.iter() {
+            if is_first {
+                is_first = false;
+            } else {
+                if_ok!(write!(f.buf, ", "));
+            }
+            if_ok!(write!(f.buf, "{}", *x))
+        }
+        write!(f.buf, "]")
+    }
+}
+
+#[cfg(not(stage0))]
+impl<T: fmt::Show> fmt::Show for ~[T] {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.as_slice().fmt(f)
+    }
+}
+
 // This works because every lifetime is a sub-lifetime of 'static
 impl<'a, A> Default for &'a [A] {
     fn default() -> &'a [A] { &'a [] }
@@ -4050,6 +4077,22 @@ mod tests {
     }
 
     #[test]
+    fn test_show() {
+        macro_rules! test_show_vec(
+            ($x:expr, $x_str:expr) => ({
+                let (x, x_str) = ($x, $x_str);
+                assert_eq!(format!("{}", x), x_str);
+                assert_eq!(format!("{}", x.as_slice()), x_str);
+            })
+        )
+        let empty: ~[int] = ~[];
+        test_show_vec!(empty, ~"[]");
+        test_show_vec!(~[1], ~"[1]");
+        test_show_vec!(~[1, 2, 3], ~"[1, 2, 3]");
+        test_show_vec!(~[~[], ~[1u], ~[1u, 1u]], ~"[[], [1], [1, 1]]");
+    }
+
+    #[test]
     fn test_vec_default() {
         use default::Default;
         macro_rules! t (
diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs
index 90bc5836240..25ba45021b3 100644
--- a/src/libstd/vec_ng.rs
+++ b/src/libstd/vec_ng.rs
@@ -22,7 +22,8 @@ use cast::{forget, transmute};
 use rt::global_heap::{malloc_raw, realloc_raw};
 use vec::{ImmutableVector, Items, MutableVector};
 use unstable::raw::Slice;
-use ptr::{offset, read_ptr};
+use ptr::read_ptr;
+use ptr::RawPtr;
 use libc::{free, c_void};
 
 pub struct Vec<T> {
@@ -135,7 +136,7 @@ impl<T> Vec<T> {
         }
 
         unsafe {
-            let end = offset(self.ptr as *T, self.len as int) as *mut T;
+            let end = (self.ptr as *T).offset(self.len as int) as *mut T;
             move_val_init(&mut *end, value);
             self.len += 1;
         }