about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-05-05 15:11:04 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-05-05 15:11:04 -0400
commit4300d4d2fa9d35ac73742c7d815ee157ce0f9c17 (patch)
tree9e5db5a04493a573f280b2c8863d0eaf0ca47c0d /src/libstd
parent6cb273ed4efb6724b1c713c3ac35d14e52999fb1 (diff)
parent063851ffa1b8388a0b70446c0209af16264e8181 (diff)
downloadrust-4300d4d2fa9d35ac73742c7d815ee157ce0f9c17.tar.gz
rust-4300d4d2fa9d35ac73742c7d815ee157ce0f9c17.zip
Merge remote-tracking branch 'mozilla/incoming' into issue-5910-dyna-freeze
Conflicts:
	src/libcore/core.rc
	src/libcore/hashmap.rs
	src/libcore/num/f32.rs
	src/libcore/num/f64.rs
	src/libcore/num/float.rs
	src/libcore/num/int-template.rs
	src/libcore/num/num.rs
	src/libcore/num/strconv.rs
	src/libcore/num/uint-template.rs
	src/libcore/ops.rs
	src/libcore/os.rs
	src/libcore/prelude.rs
	src/libcore/rt/mod.rs
	src/libcore/unstable/lang.rs
	src/librustc/driver/session.rs
	src/librustc/middle/astencode.rs
	src/librustc/middle/borrowck/check_loans.rs
	src/librustc/middle/borrowck/gather_loans.rs
	src/librustc/middle/borrowck/loan.rs
	src/librustc/middle/borrowck/preserve.rs
	src/librustc/middle/liveness.rs
	src/librustc/middle/mem_categorization.rs
	src/librustc/middle/region.rs
	src/librustc/middle/trans/base.rs
	src/librustc/middle/trans/inline.rs
	src/librustc/middle/trans/reachable.rs
	src/librustc/middle/typeck/check/_match.rs
	src/librustc/middle/typeck/check/regionck.rs
	src/librustc/util/ppaux.rs
	src/libstd/arena.rs
	src/libstd/ebml.rs
	src/libstd/json.rs
	src/libstd/serialize.rs
	src/libstd/std.rc
	src/libsyntax/ast_map.rs
	src/libsyntax/parse/parser.rs
	src/test/compile-fail/borrowck-uniq-via-box.rs
	src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs
	src/test/run-pass/borrowck-nested-calls.rs
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/arena.rs107
-rw-r--r--src/libstd/bitv.rs10
-rw-r--r--src/libstd/cmp.rs2
-rw-r--r--src/libstd/dbg.rs8
-rw-r--r--src/libstd/deque.rs2
-rw-r--r--src/libstd/ebml.rs467
-rw-r--r--src/libstd/flatpipes.rs17
-rw-r--r--src/libstd/getopts.rs8
-rw-r--r--src/libstd/json.rs530
-rw-r--r--src/libstd/list.rs33
-rw-r--r--src/libstd/net_tcp.rs2
-rw-r--r--src/libstd/net_url.rs10
-rw-r--r--src/libstd/num/bigint.rs149
-rw-r--r--src/libstd/num/complex.rs6
-rw-r--r--src/libstd/num/rational.rs8
-rw-r--r--src/libstd/serialize.rs581
-rw-r--r--src/libstd/sha1.rs8
-rw-r--r--src/libstd/sort.rs8
-rw-r--r--src/libstd/std.rc8
-rw-r--r--src/libstd/task_pool.rs1
-rw-r--r--src/libstd/tempfile.rs72
-rw-r--r--src/libstd/term.rs7
-rw-r--r--src/libstd/test.rs9
-rw-r--r--src/libstd/workcache.rs16
24 files changed, 1219 insertions, 850 deletions
diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs
index e714af5fa18..b9a09323f81 100644
--- a/src/libstd/arena.rs
+++ b/src/libstd/arena.rs
@@ -32,11 +32,10 @@
 // overhead when initializing plain-old-data and means we don't need
 // to waste time running the destructors of POD.
 
-use list;
-use list::{List, Cons, Nil};
+use list::{MutList, MutCons, MutNil};
 
 use core::at_vec;
-use core::cast::transmute;
+use core::cast::{transmute, transmute_mut_region};
 use core::cast;
 use core::libc::size_t;
 use core::ptr;
@@ -74,17 +73,17 @@ static tydesc_drop_glue_index: size_t = 3 as size_t;
 // will always stay at 0.
 struct Chunk {
     data: @[u8],
-    mut fill: uint,
+    fill: uint,
     is_pod: bool,
 }
 
 pub struct Arena {
-    // The head is seperated out from the list as a unbenchmarked
+    // The head is separated out from the list as a unbenchmarked
     // microoptimization, to avoid needing to case on the list to
     // access the head.
-    priv mut head: Chunk,
-    priv mut pod_head: Chunk,
-    priv mut chunks: @List<Chunk>,
+    priv head: Chunk,
+    priv pod_head: Chunk,
+    priv chunks: @mut MutList<Chunk>,
 }
 
 #[unsafe_destructor]
@@ -92,8 +91,10 @@ impl Drop for Arena {
     fn finalize(&self) {
         unsafe {
             destroy_chunk(&self.head);
-            for list::each(self.chunks) |chunk| {
-                if !chunk.is_pod { destroy_chunk(chunk); }
+            for self.chunks.each |chunk| {
+                if !chunk.is_pod {
+                    destroy_chunk(chunk);
+                }
             }
         }
     }
@@ -113,7 +114,7 @@ pub fn arena_with_size(initial_size: uint) -> Arena {
     Arena {
         head: chunk(initial_size, false),
         pod_head: chunk(initial_size, true),
-        chunks: @Nil,
+        chunks: @mut MutNil,
     }
 }
 
@@ -170,11 +171,11 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
 
 pub impl Arena {
     // Functions for the POD part of the arena
-    priv fn alloc_pod_grow(&self, n_bytes: uint, align: uint) -> *u8 {
+    priv fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
         // Allocate a new chunk.
         let chunk_size = at_vec::capacity(self.pod_head.data);
         let new_min_chunk_size = uint::max(n_bytes, chunk_size);
-        self.chunks = @Cons(copy self.pod_head, self.chunks);
+        self.chunks = @mut MutCons(copy self.pod_head, self.chunks);
         self.pod_head =
             chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
 
@@ -182,26 +183,27 @@ pub impl Arena {
     }
 
     #[inline(always)]
-    priv fn alloc_pod_inner(&self, n_bytes: uint, align: uint) -> *u8 {
-        let head = &mut self.pod_head;
+    priv fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
+        unsafe {
+            // XXX: Borrow check
+            let head = transmute_mut_region(&mut self.pod_head);
 
-        let start = round_up_to(head.fill, align);
-        let end = start + n_bytes;
-        if end > at_vec::capacity(head.data) {
-            return self.alloc_pod_grow(n_bytes, align);
-        }
-        head.fill = end;
+            let start = round_up_to(head.fill, align);
+            let end = start + n_bytes;
+            if end > at_vec::capacity(head.data) {
+                return self.alloc_pod_grow(n_bytes, align);
+            }
+            head.fill = end;
 
-        //debug!("idx = %u, size = %u, align = %u, fill = %u",
-        //       start, n_bytes, align, head.fill);
+            //debug!("idx = %u, size = %u, align = %u, fill = %u",
+            //       start, n_bytes, align, head.fill);
 
-        unsafe {
             ptr::offset(vec::raw::to_ptr(head.data), start)
         }
     }
 
     #[inline(always)]
-    priv fn alloc_pod<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
+    priv fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
         unsafe {
             let tydesc = sys::get_type_desc::<T>();
             let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
@@ -212,11 +214,12 @@ pub impl Arena {
     }
 
     // Functions for the non-POD part of the arena
-    priv fn alloc_nonpod_grow(&self, n_bytes: uint, align: uint) -> (*u8, *u8) {
+    priv fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
+                             -> (*u8, *u8) {
         // Allocate a new chunk.
         let chunk_size = at_vec::capacity(self.head.data);
         let new_min_chunk_size = uint::max(n_bytes, chunk_size);
-        self.chunks = @Cons(copy self.head, self.chunks);
+        self.chunks = @mut MutCons(copy self.head, self.chunks);
         self.head =
             chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
 
@@ -224,29 +227,30 @@ pub impl Arena {
     }
 
     #[inline(always)]
-    priv fn alloc_nonpod_inner(&self, n_bytes: uint, align: uint) -> (*u8, *u8) {
-        let head = &mut self.head;
-
-        let tydesc_start = head.fill;
-        let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
-        let start = round_up_to(after_tydesc, align);
-        let end = start + n_bytes;
-        if end > at_vec::capacity(head.data) {
-            return self.alloc_nonpod_grow(n_bytes, align);
-        }
-        head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
+    priv fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
+                               -> (*u8, *u8) {
+        unsafe {
+            let head = transmute_mut_region(&mut self.head);
+
+            let tydesc_start = head.fill;
+            let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
+            let start = round_up_to(after_tydesc, align);
+            let end = start + n_bytes;
+            if end > at_vec::capacity(head.data) {
+                return self.alloc_nonpod_grow(n_bytes, align);
+            }
+            head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
 
-        //debug!("idx = %u, size = %u, align = %u, fill = %u",
-        //       start, n_bytes, align, head.fill);
+            //debug!("idx = %u, size = %u, align = %u, fill = %u",
+            //       start, n_bytes, align, head.fill);
 
-        unsafe {
             let buf = vec::raw::to_ptr(head.data);
             return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
         }
     }
 
     #[inline(always)]
-    priv fn alloc_nonpod<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
+    priv fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
         unsafe {
             let tydesc = sys::get_type_desc::<T>();
             let (ty_ptr, ptr) =
@@ -268,20 +272,23 @@ pub impl Arena {
 
     // The external interface
     #[inline(always)]
-    fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
+    fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
         unsafe {
+            // XXX: Borrow check
+            let this = transmute_mut_region(self);
             if !rusti::needs_drop::<T>() {
-                self.alloc_pod(op)
-            } else {
-                self.alloc_nonpod(op)
+                return this.alloc_pod(op);
             }
+            // XXX: Borrow check
+            let this = transmute_mut_region(self);
+            this.alloc_nonpod(op)
         }
     }
 }
 
 #[test]
 fn test_arena_destructors() {
-    let arena = Arena();
+    let mut arena = Arena();
     for uint::range(0, 10) |i| {
         // Arena allocate something with drop glue to make sure it
         // doesn't leak.
@@ -292,9 +299,11 @@ fn test_arena_destructors() {
     }
 }
 
-#[test] #[should_fail] #[ignore(cfg(windows))]
+#[test]
+#[should_fail]
+#[ignore(cfg(windows))]
 fn test_arena_destructors_fail() {
-    let arena = Arena();
+    let mut arena = Arena();
     // Put some stuff in the arena.
     for uint::range(0, 10) |i| {
         // Arena allocate something with drop glue to make sure it
diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs
index d48d7af354b..ceb67fcabfa 100644
--- a/src/libstd/bitv.rs
+++ b/src/libstd/bitv.rs
@@ -1507,13 +1507,3 @@ mod tests {
         }
     }
 }
-
-//
-// Local Variables:
-// mode: rust
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
-//
diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs
index 5d7f64a7c8f..ea3793c1374 100644
--- a/src/libstd/cmp.rs
+++ b/src/libstd/cmp.rs
@@ -64,7 +64,7 @@ fn test_fuzzy_eq_eps() {
     assert!(!(&1.5f).fuzzy_eq_eps(&0.9, &0.5));
 }
 
-#[test]
+#[cfg(test)]
 mod test_complex{
     use cmp::*;
 
diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs
index 34dd6390ecc..4b2d2a60a68 100644
--- a/src/libstd/dbg.rs
+++ b/src/libstd/dbg.rs
@@ -76,11 +76,3 @@ fn test_breakpoint_should_not_abort_process_when_not_under_gdb() {
     // the process under normal circumstances
     breakpoint();
 }
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs
index 64d708e0b2e..65e71869a1f 100644
--- a/src/libstd/deque.rs
+++ b/src/libstd/deque.rs
@@ -231,7 +231,7 @@ mod tests {
         assert!(*deq.get(3) == d);
     }
 
-    #[test]
+    #[cfg(test)]
     fn test_parameterized<T:Copy + Eq + Durable>(a: T, b: T, c: T, d: T) {
         let mut deq = Deque::new();
         assert!(deq.len() == 0);
diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs
index 65ce9d8989f..864a49a1429 100644
--- a/src/libstd/ebml.rs
+++ b/src/libstd/ebml.rs
@@ -36,13 +36,27 @@ pub struct TaggedDoc {
 }
 
 pub enum EbmlEncoderTag {
-    EsUint, EsU64, EsU32, EsU16, EsU8,
-    EsInt, EsI64, EsI32, EsI16, EsI8,
-    EsBool,
-    EsStr,
-    EsF64, EsF32, EsFloat,
-    EsEnum, EsEnumVid, EsEnumBody,
-    EsVec, EsVecLen, EsVecElt,
+    EsUint,     // 0
+    EsU64,      // 1
+    EsU32,      // 2
+    EsU16,      // 3
+    EsU8,       // 4
+    EsInt,      // 5
+    EsI64,      // 6
+    EsI32,      // 7
+    EsI16,      // 8
+    EsI8,       // 9
+    EsBool,     // 10
+    EsStr,      // 11
+    EsF64,      // 12
+    EsF32,      // 13
+    EsFloat,    // 14
+    EsEnum,     // 15
+    EsEnumVid,  // 16
+    EsEnumBody, // 17
+    EsVec,      // 18
+    EsVecLen,   // 19
+    EsVecElt,   // 20
 
     EsOpaque,
 
@@ -249,18 +263,20 @@ pub mod reader {
     pub fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
     pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
 
-
     pub struct Decoder {
-        priv mut parent: Doc,
-        priv mut pos: uint,
+        priv parent: Doc,
+        priv pos: uint,
     }
 
     pub fn Decoder(d: Doc) -> Decoder {
-        Decoder { parent: d, pos: d.start }
+        Decoder {
+            parent: d,
+            pos: d.start
+        }
     }
 
     priv impl Decoder {
-        fn _check_label(&self, lbl: &str) {
+        fn _check_label(&mut self, lbl: &str) {
             if self.pos < self.parent.end {
                 let TaggedDoc { tag: r_tag, doc: r_doc } =
                     doc_at(self.parent.data, self.pos);
@@ -269,14 +285,15 @@ pub mod reader {
                     self.pos = r_doc.end;
                     let str = doc_as_str(r_doc);
                     if lbl != str {
-                        fail!(fmt!("Expected label %s but found %s", lbl,
-                            str));
+                        fail!(fmt!("Expected label %s but found %s",
+                                   lbl,
+                                   str));
                     }
                 }
             }
         }
 
-        fn next_doc(&self, exp_tag: EbmlEncoderTag) -> Doc {
+        fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> Doc {
             debug!(". next_doc(exp_tag=%?)", exp_tag);
             if self.pos >= self.parent.end {
                 fail!(~"no more documents in current node!");
@@ -298,7 +315,7 @@ pub mod reader {
             r_doc
         }
 
-        fn push_doc<T>(&self, d: Doc, f: &fn() -> T) -> T {
+        fn push_doc<T>(&mut self, d: Doc, f: &fn() -> T) -> T {
             let old_parent = self.parent;
             let old_pos = self.pos;
             self.parent = d;
@@ -309,7 +326,7 @@ pub mod reader {
             r
         }
 
-        fn _next_uint(&self, exp_tag: EbmlEncoderTag) -> uint {
+        fn _next_uint(&mut self, exp_tag: EbmlEncoderTag) -> uint {
             let r = doc_as_u32(self.next_doc(exp_tag));
             debug!("_next_uint exp_tag=%? result=%?", exp_tag, r);
             r as uint
@@ -317,21 +334,29 @@ pub mod reader {
     }
 
     pub impl Decoder {
-        fn read_opaque<R>(&self, op: &fn(Doc) -> R) -> R {
-            do self.push_doc(self.next_doc(EsOpaque)) {
-                op(copy self.parent)
-            }
+        fn read_opaque<R>(&mut self, op: &fn(&mut Decoder, Doc) -> R) -> R {
+            let doc = self.next_doc(EsOpaque);
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = doc.start;
+
+            let result = op(self, doc);
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            result
         }
     }
 
     impl serialize::Decoder for Decoder {
-        fn read_nil(&self) -> () { () }
+        fn read_nil(&mut self) -> () { () }
 
-        fn read_u64(&self) -> u64 { doc_as_u64(self.next_doc(EsU64)) }
-        fn read_u32(&self) -> u32 { doc_as_u32(self.next_doc(EsU32)) }
-        fn read_u16(&self) -> u16 { doc_as_u16(self.next_doc(EsU16)) }
-        fn read_u8 (&self) -> u8  { doc_as_u8 (self.next_doc(EsU8 )) }
-        fn read_uint(&self) -> uint {
+        fn read_u64(&mut self) -> u64 { doc_as_u64(self.next_doc(EsU64)) }
+        fn read_u32(&mut self) -> u32 { doc_as_u32(self.next_doc(EsU32)) }
+        fn read_u16(&mut self) -> u16 { doc_as_u16(self.next_doc(EsU16)) }
+        fn read_u8 (&mut self) -> u8  { doc_as_u8 (self.next_doc(EsU8 )) }
+        fn read_uint(&mut self) -> uint {
             let v = doc_as_u64(self.next_doc(EsUint));
             if v > (::core::uint::max_value as u64) {
                 fail!(fmt!("uint %? too large for this architecture", v));
@@ -339,11 +364,19 @@ pub mod reader {
             v as uint
         }
 
-        fn read_i64(&self) -> i64 { doc_as_u64(self.next_doc(EsI64)) as i64 }
-        fn read_i32(&self) -> i32 { doc_as_u32(self.next_doc(EsI32)) as i32 }
-        fn read_i16(&self) -> i16 { doc_as_u16(self.next_doc(EsI16)) as i16 }
-        fn read_i8 (&self) -> i8  { doc_as_u8 (self.next_doc(EsI8 )) as i8  }
-        fn read_int(&self) -> int {
+        fn read_i64(&mut self) -> i64 {
+            doc_as_u64(self.next_doc(EsI64)) as i64
+        }
+        fn read_i32(&mut self) -> i32 {
+            doc_as_u32(self.next_doc(EsI32)) as i32
+        }
+        fn read_i16(&mut self) -> i16 {
+            doc_as_u16(self.next_doc(EsI16)) as i16
+        }
+        fn read_i8 (&mut self) -> i8 {
+            doc_as_u8(self.next_doc(EsI8 )) as i8
+        }
+        fn read_int(&mut self) -> int {
             let v = doc_as_u64(self.next_doc(EsInt)) as i64;
             if v > (int::max_value as i64) || v < (int::min_value as i64) {
                 fail!(fmt!("int %? out of range for this architecture", v));
@@ -351,119 +384,204 @@ pub mod reader {
             v as int
         }
 
-        fn read_bool(&self) -> bool { doc_as_u8(self.next_doc(EsBool))
-                                         as bool }
+        fn read_bool(&mut self) -> bool {
+            doc_as_u8(self.next_doc(EsBool)) as bool
+        }
 
-        fn read_f64(&self) -> f64 { fail!(~"read_f64()"); }
-        fn read_f32(&self) -> f32 { fail!(~"read_f32()"); }
-        fn read_float(&self) -> float { fail!(~"read_float()"); }
-        fn read_char(&self) -> char { fail!(~"read_char()"); }
-        fn read_str(&self) -> ~str { doc_as_str(self.next_doc(EsStr)) }
+        fn read_f64(&mut self) -> f64 { fail!(~"read_f64()"); }
+        fn read_f32(&mut self) -> f32 { fail!(~"read_f32()"); }
+        fn read_float(&mut self) -> float { fail!(~"read_float()"); }
+        fn read_char(&mut self) -> char { fail!(~"read_char()"); }
+        fn read_str(&mut self) -> ~str { doc_as_str(self.next_doc(EsStr)) }
 
         // Compound types:
-        fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
+        fn read_enum<T>(&mut self,
+                        name: &str,
+                        f: &fn(&mut Decoder) -> T)
+                        -> T {
             debug!("read_enum(%s)", name);
             self._check_label(name);
-            self.push_doc(self.next_doc(EsEnum), f)
+
+            let doc = self.next_doc(EsEnum);
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = f(self);
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            result
         }
 
-        fn read_enum_variant<T>(&self, _names: &[&str], f: &fn(uint) -> T) -> T {
+        fn read_enum_variant<T>(&mut self,
+                                _: &[&str],
+                                f: &fn(&mut Decoder, uint) -> T)
+                                -> T {
             debug!("read_enum_variant()");
             let idx = self._next_uint(EsEnumVid);
             debug!("  idx=%u", idx);
-            do self.push_doc(self.next_doc(EsEnumBody)) {
-                f(idx)
-            }
+
+            let doc = self.next_doc(EsEnumBody);
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = f(self, idx);
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            result
         }
 
-        fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
+        fn read_enum_variant_arg<T>(&mut self,
+                                    idx: uint,
+                                    f: &fn(&mut Decoder) -> T) -> T {
             debug!("read_enum_variant_arg(idx=%u)", idx);
-            f()
+            f(self)
         }
 
-        fn read_enum_struct_variant<T>(&self, _names: &[&str], f: &fn(uint) -> T) -> T {
+        fn read_enum_struct_variant<T>(&mut self,
+                                       _: &[&str],
+                                       f: &fn(&mut Decoder, uint) -> T)
+                                       -> T {
             debug!("read_enum_struct_variant()");
             let idx = self._next_uint(EsEnumVid);
             debug!("  idx=%u", idx);
-            do self.push_doc(self.next_doc(EsEnumBody)) {
-                f(idx)
-            }
+
+            let doc = self.next_doc(EsEnumBody);
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = f(self, idx);
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            result
         }
 
-        fn read_enum_struct_variant_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
+        fn read_enum_struct_variant_field<T>(&mut self,
+                                             name: &str,
+                                             idx: uint,
+                                             f: &fn(&mut Decoder) -> T)
+                                             -> T {
             debug!("read_enum_struct_variant_arg(name=%?, idx=%u)", name, idx);
-            f()
+            f(self)
         }
 
-        fn read_struct<T>(&self, name: &str, _len: uint, f: &fn() -> T) -> T {
+        fn read_struct<T>(&mut self,
+                          name: &str,
+                          _: uint,
+                          f: &fn(&mut Decoder) -> T)
+                          -> T {
             debug!("read_struct(name=%s)", name);
-            f()
+            f(self)
         }
 
-        fn read_struct_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
+        fn read_struct_field<T>(&mut self,
+                                name: &str,
+                                idx: uint,
+                                f: &fn(&mut Decoder) -> T)
+                                -> T {
             debug!("read_struct_field(name=%?, idx=%u)", name, idx);
             self._check_label(name);
-            f()
+            f(self)
         }
 
-        fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T {
+        fn read_tuple<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T {
             debug!("read_tuple()");
             self.read_seq(f)
         }
 
-        fn read_tuple_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
+        fn read_tuple_arg<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T)
+                             -> T {
             debug!("read_tuple_arg(idx=%u)", idx);
             self.read_seq_elt(idx, f)
         }
 
-        fn read_tuple_struct<T>(&self, name: &str, f: &fn(uint) -> T) -> T {
+        fn read_tuple_struct<T>(&mut self,
+                                name: &str,
+                                f: &fn(&mut Decoder, uint) -> T)
+                                -> T {
             debug!("read_tuple_struct(name=%?)", name);
             self.read_tuple(f)
         }
 
-        fn read_tuple_struct_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
+        fn read_tuple_struct_arg<T>(&mut self,
+                                    idx: uint,
+                                    f: &fn(&mut Decoder) -> T)
+                                    -> T {
             debug!("read_tuple_struct_arg(idx=%u)", idx);
             self.read_tuple_arg(idx, f)
         }
 
-        fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
+        fn read_option<T>(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T {
             debug!("read_option()");
-            do self.read_enum("Option") || {
-                do self.read_enum_variant(["None", "Some"]) |idx| {
+            do self.read_enum("Option") |this| {
+                do this.read_enum_variant(["None", "Some"]) |this, idx| {
                     match idx {
-                        0 => f(false),
-                        1 => f(true),
+                        0 => f(this, false),
+                        1 => f(this, true),
                         _ => fail!(),
                     }
                 }
             }
         }
 
-        fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
+        fn read_seq<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T {
             debug!("read_seq()");
-            do self.push_doc(self.next_doc(EsVec)) {
-                let len = self._next_uint(EsVecLen);
-                debug!("  len=%u", len);
-                f(len)
-            }
+            let doc = self.next_doc(EsVec);
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let len = self._next_uint(EsVecLen);
+            debug!("  len=%u", len);
+            let result = f(self, len);
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            result
         }
 
-        fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
+        fn read_seq_elt<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T)
+                           -> T {
             debug!("read_seq_elt(idx=%u)", idx);
-            self.push_doc(self.next_doc(EsVecElt), f)
+            let doc = self.next_doc(EsVecElt);
+
+            let (old_parent, old_pos) = (self.parent, self.pos);
+            self.parent = doc;
+            self.pos = self.parent.start;
+
+            let result = f(self);
+
+            self.parent = old_parent;
+            self.pos = old_pos;
+            result
         }
 
-        fn read_map<T>(&self, _f: &fn(uint) -> T) -> T {
+        fn read_map<T>(&mut self, _: &fn(&mut Decoder, uint) -> T) -> T {
             debug!("read_map()");
             fail!(~"read_map is unimplemented");
         }
 
-        fn read_map_elt_key<T>(&self, idx: uint, _f: &fn() -> T) -> T {
+        fn read_map_elt_key<T>(&mut self,
+                               idx: uint,
+                               _: &fn(&mut Decoder) -> T)
+                               -> T {
             debug!("read_map_elt_key(idx=%u)", idx);
             fail!(~"read_map_elt_val is unimplemented");
         }
 
-        fn read_map_elt_val<T>(&self, idx: uint, _f: &fn() -> T) -> T {
+        fn read_map_elt_val<T>(&mut self,
+                               idx: uint,
+                               _: &fn(&mut Decoder) -> T)
+                               -> T {
             debug!("read_map_elt_val(idx=%u)", idx);
             fail!(~"read_map_elt_val is unimplemented");
         }
@@ -513,7 +631,7 @@ pub mod writer {
 
     // FIXME (#2741): Provide a function to write the standard ebml header.
     pub impl Encoder {
-        fn start_tag(&self, tag_id: uint) {
+        fn start_tag(&mut self, tag_id: uint) {
             debug!("Start tag %u", tag_id);
 
             // Write the enum ID:
@@ -525,7 +643,7 @@ pub mod writer {
             self.writer.write(zeroes);
         }
 
-        fn end_tag(&self) {
+        fn end_tag(&mut self) {
             let last_size_pos = self.size_positions.pop();
             let cur_pos = self.writer.tell();
             self.writer.seek(last_size_pos as int, io::SeekSet);
@@ -536,72 +654,72 @@ pub mod writer {
             debug!("End tag (size = %u)", size);
         }
 
-        fn wr_tag(&self, tag_id: uint, blk: &fn()) {
+        fn wr_tag(&mut self, tag_id: uint, blk: &fn()) {
             self.start_tag(tag_id);
             blk();
             self.end_tag();
         }
 
-        fn wr_tagged_bytes(&self, tag_id: uint, b: &[u8]) {
+        fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) {
             write_vuint(self.writer, tag_id);
             write_vuint(self.writer, vec::len(b));
             self.writer.write(b);
         }
 
-        fn wr_tagged_u64(&self, tag_id: uint, v: u64) {
+        fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) {
             do io::u64_to_be_bytes(v, 8u) |v| {
                 self.wr_tagged_bytes(tag_id, v);
             }
         }
 
-        fn wr_tagged_u32(&self, tag_id: uint, v: u32) {
+        fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) {
             do io::u64_to_be_bytes(v as u64, 4u) |v| {
                 self.wr_tagged_bytes(tag_id, v);
             }
         }
 
-        fn wr_tagged_u16(&self, tag_id: uint, v: u16) {
+        fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) {
             do io::u64_to_be_bytes(v as u64, 2u) |v| {
                 self.wr_tagged_bytes(tag_id, v);
             }
         }
 
-        fn wr_tagged_u8(&self, tag_id: uint, v: u8) {
+        fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) {
             self.wr_tagged_bytes(tag_id, &[v]);
         }
 
-        fn wr_tagged_i64(&self, tag_id: uint, v: i64) {
+        fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) {
             do io::u64_to_be_bytes(v as u64, 8u) |v| {
                 self.wr_tagged_bytes(tag_id, v);
             }
         }
 
-        fn wr_tagged_i32(&self, tag_id: uint, v: i32) {
+        fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) {
             do io::u64_to_be_bytes(v as u64, 4u) |v| {
                 self.wr_tagged_bytes(tag_id, v);
             }
         }
 
-        fn wr_tagged_i16(&self, tag_id: uint, v: i16) {
+        fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) {
             do io::u64_to_be_bytes(v as u64, 2u) |v| {
                 self.wr_tagged_bytes(tag_id, v);
             }
         }
 
-        fn wr_tagged_i8(&self, tag_id: uint, v: i8) {
+        fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) {
             self.wr_tagged_bytes(tag_id, &[v as u8]);
         }
 
-        fn wr_tagged_str(&self, tag_id: uint, v: &str) {
+        fn wr_tagged_str(&mut self, tag_id: uint, v: &str) {
             str::byte_slice(v, |b| self.wr_tagged_bytes(tag_id, b));
         }
 
-        fn wr_bytes(&self, b: &[u8]) {
+        fn wr_bytes(&mut self, b: &[u8]) {
             debug!("Write %u bytes", vec::len(b));
             self.writer.write(b);
         }
 
-        fn wr_str(&self, s: &str) {
+        fn wr_str(&mut self, s: &str) {
             debug!("Write str: %?", s);
             self.writer.write(str::to_bytes(s));
         }
@@ -612,16 +730,16 @@ pub mod writer {
 
     // Set to true to generate more debugging in EBML code.
     // Totally lame approach.
-    static debug: bool = false;
+    static debug: bool = true;
 
     priv impl Encoder {
         // used internally to emit things like the vector length and so on
-        fn _emit_tagged_uint(&self, t: EbmlEncoderTag, v: uint) {
+        fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) {
             assert!(v <= 0xFFFF_FFFF_u); // FIXME(#6130) assert warns on 32-bit
             self.wr_tagged_u32(t as uint, v as u32);
         }
 
-        fn _emit_label(&self, label: &str) {
+        fn _emit_label(&mut self, label: &str) {
             // There are various strings that we have access to, such as
             // the name of a record field, which do not actually appear in
             // the encoded EBML (normally).  This is just for
@@ -633,118 +751,169 @@ pub mod writer {
     }
 
     pub impl Encoder {
-        fn emit_opaque(&self, f: &fn()) {
-            do self.wr_tag(EsOpaque as uint) {
-                f()
-            }
+        fn emit_opaque(&mut self, f: &fn(&mut Encoder)) {
+            self.start_tag(EsOpaque as uint);
+            f(self);
+            self.end_tag();
         }
     }
 
     impl ::serialize::Encoder for Encoder {
-        fn emit_nil(&self) {}
+        fn emit_nil(&mut self) {}
 
-        fn emit_uint(&self, v: uint) {
+        fn emit_uint(&mut self, v: uint) {
             self.wr_tagged_u64(EsUint as uint, v as u64);
         }
-        fn emit_u64(&self, v: u64) { self.wr_tagged_u64(EsU64 as uint, v); }
-        fn emit_u32(&self, v: u32) { self.wr_tagged_u32(EsU32 as uint, v); }
-        fn emit_u16(&self, v: u16) { self.wr_tagged_u16(EsU16 as uint, v); }
-        fn emit_u8(&self, v: u8)   { self.wr_tagged_u8 (EsU8  as uint, v); }
+        fn emit_u64(&mut self, v: u64) {
+            self.wr_tagged_u64(EsU64 as uint, v);
+        }
+        fn emit_u32(&mut self, v: u32) {
+            self.wr_tagged_u32(EsU32 as uint, v);
+        }
+        fn emit_u16(&mut self, v: u16) {
+            self.wr_tagged_u16(EsU16 as uint, v);
+        }
+        fn emit_u8(&mut self, v: u8) {
+            self.wr_tagged_u8(EsU8 as uint, v);
+        }
 
-        fn emit_int(&self, v: int) {
+        fn emit_int(&mut self, v: int) {
             self.wr_tagged_i64(EsInt as uint, v as i64);
         }
-        fn emit_i64(&self, v: i64) { self.wr_tagged_i64(EsI64 as uint, v); }
-        fn emit_i32(&self, v: i32) { self.wr_tagged_i32(EsI32 as uint, v); }
-        fn emit_i16(&self, v: i16) { self.wr_tagged_i16(EsI16 as uint, v); }
-        fn emit_i8(&self, v: i8)   { self.wr_tagged_i8 (EsI8  as uint, v); }
+        fn emit_i64(&mut self, v: i64) {
+            self.wr_tagged_i64(EsI64 as uint, v);
+        }
+        fn emit_i32(&mut self, v: i32) {
+            self.wr_tagged_i32(EsI32 as uint, v);
+        }
+        fn emit_i16(&mut self, v: i16) {
+            self.wr_tagged_i16(EsI16 as uint, v);
+        }
+        fn emit_i8(&mut self, v: i8) {
+            self.wr_tagged_i8(EsI8 as uint, v);
+        }
 
-        fn emit_bool(&self, v: bool) {
+        fn emit_bool(&mut self, v: bool) {
             self.wr_tagged_u8(EsBool as uint, v as u8)
         }
 
         // FIXME (#2742): implement these
-        fn emit_f64(&self, _v: f64) {
+        fn emit_f64(&mut self, _v: f64) {
             fail!(~"Unimplemented: serializing an f64");
         }
-        fn emit_f32(&self, _v: f32) {
+        fn emit_f32(&mut self, _v: f32) {
             fail!(~"Unimplemented: serializing an f32");
         }
-        fn emit_float(&self, _v: float) {
+        fn emit_float(&mut self, _v: float) {
             fail!(~"Unimplemented: serializing a float");
         }
 
-        fn emit_char(&self, _v: char) {
+        fn emit_char(&mut self, _v: char) {
             fail!(~"Unimplemented: serializing a char");
         }
 
-        fn emit_str(&self, v: &str) {
+        fn emit_str(&mut self, v: &str) {
             self.wr_tagged_str(EsStr as uint, v)
         }
 
-        fn emit_enum(&self, name: &str, f: &fn()) {
+        fn emit_enum(&mut self, name: &str, f: &fn(&mut Encoder)) {
             self._emit_label(name);
-            self.wr_tag(EsEnum as uint, f)
+            self.start_tag(EsEnum as uint);
+            f(self);
+            self.end_tag();
         }
 
-        fn emit_enum_variant(&self, _v_name: &str, v_id: uint, _cnt: uint,
-                             f: &fn()) {
+        fn emit_enum_variant(&mut self,
+                             _: &str,
+                             v_id: uint,
+                             _: uint,
+                             f: &fn(&mut Encoder)) {
             self._emit_tagged_uint(EsEnumVid, v_id);
-            self.wr_tag(EsEnumBody as uint, f)
+            self.start_tag(EsEnumBody as uint);
+            f(self);
+            self.end_tag();
         }
 
-        fn emit_enum_variant_arg(&self, _idx: uint, f: &fn()) { f() }
+        fn emit_enum_variant_arg(&mut self, _: uint, f: &fn(&mut Encoder)) {
+            f(self)
+        }
 
-        fn emit_enum_struct_variant(&self, v_name: &str, v_id: uint, cnt: uint, f: &fn()) {
+        fn emit_enum_struct_variant(&mut self,
+                                    v_name: &str,
+                                    v_id: uint,
+                                    cnt: uint,
+                                    f: &fn(&mut Encoder)) {
             self.emit_enum_variant(v_name, v_id, cnt, f)
         }
 
-        fn emit_enum_struct_variant_field(&self, _f_name: &str, idx: uint, f: &fn()) {
+        fn emit_enum_struct_variant_field(&mut self,
+                                          _: &str,
+                                          idx: uint,
+                                          f: &fn(&mut Encoder)) {
             self.emit_enum_variant_arg(idx, f)
         }
 
-        fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) { f() }
-        fn emit_struct_field(&self, name: &str, _idx: uint, f: &fn()) {
+        fn emit_struct(&mut self, _: &str, _len: uint, f: &fn(&mut Encoder)) {
+            f(self)
+        }
+
+        fn emit_struct_field(&mut self,
+                             name: &str,
+                             _: uint,
+                             f: &fn(&mut Encoder)) {
             self._emit_label(name);
-            f()
+            f(self)
         }
 
-        fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
-        fn emit_tuple_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
+        fn emit_tuple(&mut self, len: uint, f: &fn(&mut Encoder)) {
+            self.emit_seq(len, f)
+        }
+        fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) {
+            self.emit_seq_elt(idx, f)
+        }
 
-        fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) { self.emit_seq(len, f) }
-        fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
+        fn emit_tuple_struct(&mut self,
+                             _: &str,
+                             len: uint,
+                             f: &fn(&mut Encoder)) {
+            self.emit_seq(len, f)
+        }
+        fn emit_tuple_struct_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) {
+            self.emit_seq_elt(idx, f)
+        }
 
-        fn emit_option(&self, f: &fn()) {
+        fn emit_option(&mut self, f: &fn(&mut Encoder)) {
             self.emit_enum("Option", f);
         }
-        fn emit_option_none(&self) {
-            self.emit_enum_variant("None", 0, 0, || ())
+        fn emit_option_none(&mut self) {
+            self.emit_enum_variant("None", 0, 0, |_| ())
         }
-        fn emit_option_some(&self, f: &fn()) {
+        fn emit_option_some(&mut self, f: &fn(&mut Encoder)) {
             self.emit_enum_variant("Some", 1, 1, f)
         }
 
-        fn emit_seq(&self, len: uint, f: &fn()) {
-            do self.wr_tag(EsVec as uint) {
-                self._emit_tagged_uint(EsVecLen, len);
-                f()
-            }
+        fn emit_seq(&mut self, len: uint, f: &fn(&mut Encoder)) {
+            self.start_tag(EsVec as uint);
+            self._emit_tagged_uint(EsVecLen, len);
+            f(self);
+            self.end_tag();
         }
 
-        fn emit_seq_elt(&self, _idx: uint, f: &fn()) {
-            self.wr_tag(EsVecElt as uint, f)
+        fn emit_seq_elt(&mut self, _idx: uint, f: &fn(&mut Encoder)) {
+            self.start_tag(EsVecElt as uint);
+            f(self);
+            self.end_tag();
         }
 
-        fn emit_map(&self, _len: uint, _f: &fn()) {
+        fn emit_map(&mut self, _len: uint, _f: &fn(&mut Encoder)) {
             fail!(~"emit_map is unimplemented");
         }
 
-        fn emit_map_elt_key(&self, _idx: uint, _f: &fn()) {
+        fn emit_map_elt_key(&mut self, _idx: uint, _f: &fn(&mut Encoder)) {
             fail!(~"emit_map_elt_key is unimplemented");
         }
 
-        fn emit_map_elt_val(&self, _idx: uint, _f: &fn()) {
+        fn emit_map_elt_val(&mut self, _idx: uint, _f: &fn(&mut Encoder)) {
             fail!(~"emit_map_elt_val is unimplemented");
         }
     }
@@ -768,12 +937,12 @@ mod tests {
         fn test_v(v: Option<int>) {
             debug!("v == %?", v);
             let bytes = do io::with_bytes_writer |wr| {
-                let ebml_w = writer::Encoder(wr);
-                v.encode(&ebml_w)
+                let mut ebml_w = writer::Encoder(wr);
+                v.encode(&mut ebml_w)
             };
             let ebml_doc = reader::Doc(@bytes);
-            let deser = reader::Decoder(ebml_doc);
-            let v1 = serialize::Decodable::decode(&deser);
+            let mut deser = reader::Decoder(ebml_doc);
+            let v1 = serialize::Decodable::decode(&mut deser);
             debug!("v1 == %?", v1);
             assert!(v == v1);
         }
diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs
index bd0acb849fc..88de53f3605 100644
--- a/src/libstd/flatpipes.rs
+++ b/src/libstd/flatpipes.rs
@@ -439,19 +439,23 @@ pub mod flatteners {
     */
 
     pub fn deserialize_buffer<D: Decoder + FromReader,
-                              T: Decodable<D>>(buf: &[u8]) -> T {
+                              T: Decodable<D>>(
+                              buf: &[u8])
+                              -> T {
         let buf = vec::from_slice(buf);
         let buf_reader = @BufReader::new(buf);
         let reader = buf_reader as @Reader;
-        let deser: D = FromReader::from_reader(reader);
-        Decodable::decode(&deser)
+        let mut deser: D = FromReader::from_reader(reader);
+        Decodable::decode(&mut deser)
     }
 
     pub fn serialize_value<D: Encoder + FromWriter,
-                           T: Encodable<D>>(val: &T) -> ~[u8] {
+                           T: Encodable<D>>(
+                           val: &T)
+                           -> ~[u8] {
         do io::with_bytes_writer |writer| {
-            let ser = FromWriter::from_writer(writer);
-            val.encode(&ser);
+            let mut ser = FromWriter::from_writer(writer);
+            val.encode(&mut ser);
         }
     }
 
@@ -649,6 +653,7 @@ mod test {
     }
 
     #[test]
+    #[ignore(reason = "FIXME #6211 failing on linux snapshot machine")]
     fn test_serializing_pipes() {
         let (port, chan) = serial::pipe_stream();
 
diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs
index fda5c105da5..c03042fe9c2 100644
--- a/src/libstd/getopts.rs
+++ b/src/libstd/getopts.rs
@@ -1374,11 +1374,3 @@ Options:
         assert!(usage == expected)
     }
 }
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/json.rs b/src/libstd/json.rs
index 5d5b0bd952f..3960a07dfce 100644
--- a/src/libstd/json.rs
+++ b/src/libstd/json.rs
@@ -72,25 +72,27 @@ pub struct Encoder {
 }
 
 pub fn Encoder(wr: @io::Writer) -> Encoder {
-    Encoder { wr: wr }
+    Encoder {
+        wr: wr
+    }
 }
 
 impl serialize::Encoder for Encoder {
-    fn emit_nil(&self) { self.wr.write_str("null") }
+    fn emit_nil(&mut self) { self.wr.write_str("null") }
 
-    fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
-    fn emit_u64(&self, v: u64) { self.emit_float(v as float); }
-    fn emit_u32(&self, v: u32) { self.emit_float(v as float); }
-    fn emit_u16(&self, v: u16) { self.emit_float(v as float); }
-    fn emit_u8(&self, v: u8)   { self.emit_float(v as float); }
+    fn emit_uint(&mut self, v: uint) { self.emit_float(v as float); }
+    fn emit_u64(&mut self, v: u64) { self.emit_float(v as float); }
+    fn emit_u32(&mut self, v: u32) { self.emit_float(v as float); }
+    fn emit_u16(&mut self, v: u16) { self.emit_float(v as float); }
+    fn emit_u8(&mut self, v: u8)   { self.emit_float(v as float); }
 
-    fn emit_int(&self, v: int) { self.emit_float(v as float); }
-    fn emit_i64(&self, v: i64) { self.emit_float(v as float); }
-    fn emit_i32(&self, v: i32) { self.emit_float(v as float); }
-    fn emit_i16(&self, v: i16) { self.emit_float(v as float); }
-    fn emit_i8(&self, v: i8)   { self.emit_float(v as float); }
+    fn emit_int(&mut self, v: int) { self.emit_float(v as float); }
+    fn emit_i64(&mut self, v: i64) { self.emit_float(v as float); }
+    fn emit_i32(&mut self, v: i32) { self.emit_float(v as float); }
+    fn emit_i16(&mut self, v: i16) { self.emit_float(v as float); }
+    fn emit_i8(&mut self, v: i8)   { self.emit_float(v as float); }
 
-    fn emit_bool(&self, v: bool) {
+    fn emit_bool(&mut self, v: bool) {
         if v {
             self.wr.write_str("true");
         } else {
@@ -98,18 +100,22 @@ impl serialize::Encoder for Encoder {
         }
     }
 
-    fn emit_f64(&self, v: f64) { self.emit_float(v as float); }
-    fn emit_f32(&self, v: f32) { self.emit_float(v as float); }
-    fn emit_float(&self, v: float) {
+    fn emit_f64(&mut self, v: f64) { self.emit_float(v as float); }
+    fn emit_f32(&mut self, v: f32) { self.emit_float(v as float); }
+    fn emit_float(&mut self, v: float) {
         self.wr.write_str(float::to_str_digits(v, 6u));
     }
 
-    fn emit_char(&self, v: char) { self.emit_str(str::from_char(v)) }
-    fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)) }
+    fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) }
+    fn emit_str(&mut self, v: &str) { self.wr.write_str(escape_str(v)) }
 
-    fn emit_enum(&self, _name: &str, f: &fn()) { f() }
+    fn emit_enum(&mut self, _name: &str, f: &fn(&mut Encoder)) { f(self) }
 
-    fn emit_enum_variant(&self, name: &str, _id: uint, cnt: uint, f: &fn()) {
+    fn emit_enum_variant(&mut self,
+                         name: &str,
+                         _id: uint,
+                         cnt: uint,
+                         f: &fn(&mut Encoder)) {
         // enums are encoded as strings or vectors:
         // Bunny => "Bunny"
         // Kangaroo(34,"William") => ["Kangaroo",[34,"William"]]
@@ -120,71 +126,97 @@ impl serialize::Encoder for Encoder {
             self.wr.write_char('[');
             self.wr.write_str(escape_str(name));
             self.wr.write_char(',');
-            f();
+            f(self);
             self.wr.write_char(']');
         }
     }
 
-    fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
-        if idx != 0 {self.wr.write_char(',');}
-        f();
+    fn emit_enum_variant_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) {
+        if idx != 0 {
+            self.wr.write_char(',');
+        }
+        f(self);
     }
 
-    fn emit_enum_struct_variant(&self, name: &str, id: uint, cnt: uint, f: &fn()) {
+    fn emit_enum_struct_variant(&mut self,
+                                name: &str,
+                                id: uint,
+                                cnt: uint,
+                                f: &fn(&mut Encoder)) {
         self.emit_enum_variant(name, id, cnt, f)
     }
 
-    fn emit_enum_struct_variant_field(&self, _field: &str, idx: uint, f: &fn()) {
+    fn emit_enum_struct_variant_field(&mut self,
+                                      _: &str,
+                                      idx: uint,
+                                      f: &fn(&mut Encoder)) {
         self.emit_enum_variant_arg(idx, f)
     }
 
-    fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) {
+    fn emit_struct(&mut self, _: &str, _: uint, f: &fn(&mut Encoder)) {
         self.wr.write_char('{');
-        f();
+        f(self);
         self.wr.write_char('}');
     }
-    fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
+
+    fn emit_struct_field(&mut self,
+                         name: &str,
+                         idx: uint,
+                         f: &fn(&mut Encoder)) {
         if idx != 0 { self.wr.write_char(','); }
         self.wr.write_str(escape_str(name));
         self.wr.write_char(':');
-        f();
+        f(self);
     }
 
-    fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
-    fn emit_tuple_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
+    fn emit_tuple(&mut self, len: uint, f: &fn(&mut Encoder)) {
+        self.emit_seq(len, f)
+    }
+    fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) {
+        self.emit_seq_elt(idx, f)
+    }
 
-    fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) { self.emit_seq(len, f) }
-    fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
+    fn emit_tuple_struct(&mut self,
+                         _name: &str,
+                         len: uint,
+                         f: &fn(&mut Encoder)) {
+        self.emit_seq(len, f)
+    }
+    fn emit_tuple_struct_arg(&mut self, idx: uint, f: &fn(&mut Encoder)) {
+        self.emit_seq_elt(idx, f)
+    }
 
-    fn emit_option(&self, f: &fn()) { f(); }
-    fn emit_option_none(&self) { self.emit_nil(); }
-    fn emit_option_some(&self, f: &fn()) { f(); }
+    fn emit_option(&mut self, f: &fn(&mut Encoder)) { f(self); }
+    fn emit_option_none(&mut self) { self.emit_nil(); }
+    fn emit_option_some(&mut self, f: &fn(&mut Encoder)) { f(self); }
 
-    fn emit_seq(&self, _len: uint, f: &fn()) {
+    fn emit_seq(&mut self, _len: uint, f: &fn(&mut Encoder)) {
         self.wr.write_char('[');
-        f();
+        f(self);
         self.wr.write_char(']');
     }
 
-    fn emit_seq_elt(&self, idx: uint, f: &fn()) {
-        if idx != 0 { self.wr.write_char(','); }
-        f()
+    fn emit_seq_elt(&mut self, idx: uint, f: &fn(&mut Encoder)) {
+        if idx != 0 {
+            self.wr.write_char(',');
+        }
+        f(self)
     }
 
-    fn emit_map(&self, _len: uint, f: &fn()) {
+    fn emit_map(&mut self, _len: uint, f: &fn(&mut Encoder)) {
         self.wr.write_char('{');
-        f();
+        f(self);
         self.wr.write_char('}');
     }
 
-    fn emit_map_elt_key(&self, idx: uint, f: &fn()) {
+    fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Encoder)) {
         if idx != 0 { self.wr.write_char(','); }
-        f()
+        f(self)
     }
 
-    fn emit_map_elt_val(&self, _idx: uint, f: &fn()) {
+    fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut Encoder)) {
         self.wr.write_char(':');
-        f()
+        f(self)
     }
 }
 
@@ -194,25 +226,28 @@ pub struct PrettyEncoder {
 }
 
 pub fn PrettyEncoder(wr: @io::Writer) -> PrettyEncoder {
-    PrettyEncoder { wr: wr, indent: 0 }
+    PrettyEncoder {
+        wr: wr,
+        indent: 0,
+    }
 }
 
 impl serialize::Encoder for PrettyEncoder {
-    fn emit_nil(&self) { self.wr.write_str("null") }
+    fn emit_nil(&mut self) { self.wr.write_str("null") }
 
-    fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
-    fn emit_u64(&self, v: u64) { self.emit_float(v as float); }
-    fn emit_u32(&self, v: u32) { self.emit_float(v as float); }
-    fn emit_u16(&self, v: u16) { self.emit_float(v as float); }
-    fn emit_u8(&self, v: u8)   { self.emit_float(v as float); }
+    fn emit_uint(&mut self, v: uint) { self.emit_float(v as float); }
+    fn emit_u64(&mut self, v: u64) { self.emit_float(v as float); }
+    fn emit_u32(&mut self, v: u32) { self.emit_float(v as float); }
+    fn emit_u16(&mut self, v: u16) { self.emit_float(v as float); }
+    fn emit_u8(&mut self, v: u8)   { self.emit_float(v as float); }
 
-    fn emit_int(&self, v: int) { self.emit_float(v as float); }
-    fn emit_i64(&self, v: i64) { self.emit_float(v as float); }
-    fn emit_i32(&self, v: i32) { self.emit_float(v as float); }
-    fn emit_i16(&self, v: i16) { self.emit_float(v as float); }
-    fn emit_i8(&self, v: i8)   { self.emit_float(v as float); }
+    fn emit_int(&mut self, v: int) { self.emit_float(v as float); }
+    fn emit_i64(&mut self, v: i64) { self.emit_float(v as float); }
+    fn emit_i32(&mut self, v: i32) { self.emit_float(v as float); }
+    fn emit_i16(&mut self, v: i16) { self.emit_float(v as float); }
+    fn emit_i8(&mut self, v: i8)   { self.emit_float(v as float); }
 
-    fn emit_bool(&self, v: bool) {
+    fn emit_bool(&mut self, v: bool) {
         if v {
             self.wr.write_str("true");
         } else {
@@ -220,18 +255,24 @@ impl serialize::Encoder for PrettyEncoder {
         }
     }
 
-    fn emit_f64(&self, v: f64) { self.emit_float(v as float); }
-    fn emit_f32(&self, v: f32) { self.emit_float(v as float); }
-    fn emit_float(&self, v: float) {
+    fn emit_f64(&mut self, v: f64) { self.emit_float(v as float); }
+    fn emit_f32(&mut self, v: f32) { self.emit_float(v as float); }
+    fn emit_float(&mut self, v: float) {
         self.wr.write_str(float::to_str_digits(v, 6u));
     }
 
-    fn emit_char(&self, v: char) { self.emit_str(str::from_char(v)) }
-    fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)); }
+    fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) }
+    fn emit_str(&mut self, v: &str) { self.wr.write_str(escape_str(v)); }
 
-    fn emit_enum(&self, _name: &str, f: &fn()) { f() }
+    fn emit_enum(&mut self, _name: &str, f: &fn(&mut PrettyEncoder)) {
+        f(self)
+    }
 
-    fn emit_enum_variant(&self, name: &str, _id: uint, cnt: uint, f: &fn()) {
+    fn emit_enum_variant(&mut self,
+                         name: &str,
+                         _: uint,
+                         cnt: uint,
+                         f: &fn(&mut PrettyEncoder)) {
         if cnt == 0 {
             self.wr.write_str(escape_str(name));
         } else {
@@ -241,7 +282,7 @@ impl serialize::Encoder for PrettyEncoder {
             self.wr.write_str(spaces(self.indent));
             self.wr.write_str(escape_str(name));
             self.wr.write_str(",\n");
-            f();
+            f(self);
             self.wr.write_char('\n');
             self.indent -= 2;
             self.wr.write_str(spaces(self.indent));
@@ -249,37 +290,53 @@ impl serialize::Encoder for PrettyEncoder {
         }
     }
 
-    fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
+    fn emit_enum_variant_arg(&mut self,
+                             idx: uint,
+                             f: &fn(&mut PrettyEncoder)) {
         if idx != 0 {
             self.wr.write_str(",\n");
         }
         self.wr.write_str(spaces(self.indent));
-        f()
+        f(self)
     }
 
-    fn emit_enum_struct_variant(&self, name: &str, id: uint, cnt: uint, f: &fn()) {
+    fn emit_enum_struct_variant(&mut self,
+                                name: &str,
+                                id: uint,
+                                cnt: uint,
+                                f: &fn(&mut PrettyEncoder)) {
         self.emit_enum_variant(name, id, cnt, f)
     }
 
-    fn emit_enum_struct_variant_field(&self, _field: &str, idx: uint, f: &fn()) {
+    fn emit_enum_struct_variant_field(&mut self,
+                                      _: &str,
+                                      idx: uint,
+                                      f: &fn(&mut PrettyEncoder)) {
         self.emit_enum_variant_arg(idx, f)
     }
 
 
-    fn emit_struct(&self, _name: &str, len: uint, f: &fn()) {
+    fn emit_struct(&mut self,
+                   _: &str,
+                   len: uint,
+                   f: &fn(&mut PrettyEncoder)) {
         if len == 0 {
             self.wr.write_str("{}");
         } else {
             self.wr.write_char('{');
             self.indent += 2;
-            f();
+            f(self);
             self.wr.write_char('\n');
             self.indent -= 2;
             self.wr.write_str(spaces(self.indent));
             self.wr.write_char('}');
         }
     }
-    fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
+
+    fn emit_struct_field(&mut self,
+                         name: &str,
+                         idx: uint,
+                         f: &fn(&mut PrettyEncoder)) {
         if idx == 0 {
             self.wr.write_char('\n');
         } else {
@@ -288,73 +345,88 @@ impl serialize::Encoder for PrettyEncoder {
         self.wr.write_str(spaces(self.indent));
         self.wr.write_str(escape_str(name));
         self.wr.write_str(": ");
-        f();
+        f(self);
     }
 
-    fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
-    fn emit_tuple_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
+    fn emit_tuple(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) {
+        self.emit_seq(len, f)
+    }
+    fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) {
+        self.emit_seq_elt(idx, f)
+    }
 
-    fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) { self.emit_seq(len, f) }
-    fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
+    fn emit_tuple_struct(&mut self,
+                         _: &str,
+                         len: uint,
+                         f: &fn(&mut PrettyEncoder)) {
+        self.emit_seq(len, f)
+    }
+    fn emit_tuple_struct_arg(&mut self,
+                             idx: uint,
+                             f: &fn(&mut PrettyEncoder)) {
+        self.emit_seq_elt(idx, f)
+    }
 
-    fn emit_option(&self, f: &fn()) { f(); }
-    fn emit_option_none(&self) { self.emit_nil(); }
-    fn emit_option_some(&self, f: &fn()) { f(); }
+    fn emit_option(&mut self, f: &fn(&mut PrettyEncoder)) { f(self); }
+    fn emit_option_none(&mut self) { self.emit_nil(); }
+    fn emit_option_some(&mut self, f: &fn(&mut PrettyEncoder)) { f(self); }
 
-    fn emit_seq(&self, len: uint, f: &fn()) {
+    fn emit_seq(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) {
         if len == 0 {
             self.wr.write_str("[]");
         } else {
             self.wr.write_char('[');
             self.indent += 2;
-            f();
+            f(self);
             self.wr.write_char('\n');
             self.indent -= 2;
             self.wr.write_str(spaces(self.indent));
             self.wr.write_char(']');
         }
     }
-    fn emit_seq_elt(&self, idx: uint, f: &fn()) {
+
+    fn emit_seq_elt(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) {
         if idx == 0 {
             self.wr.write_char('\n');
         } else {
             self.wr.write_str(",\n");
         }
         self.wr.write_str(spaces(self.indent));
-        f()
+        f(self)
     }
 
-    fn emit_map(&self, len: uint, f: &fn()) {
+    fn emit_map(&mut self, len: uint, f: &fn(&mut PrettyEncoder)) {
         if len == 0 {
             self.wr.write_str("{}");
         } else {
             self.wr.write_char('{');
             self.indent += 2;
-            f();
+            f(self);
             self.wr.write_char('\n');
             self.indent -= 2;
             self.wr.write_str(spaces(self.indent));
             self.wr.write_char('}');
         }
     }
-    fn emit_map_elt_key(&self, idx: uint, f: &fn()) {
+
+    fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut PrettyEncoder)) {
         if idx == 0 {
             self.wr.write_char('\n');
         } else {
             self.wr.write_str(",\n");
         }
         self.wr.write_str(spaces(self.indent));
-        f();
+        f(self);
     }
 
-    fn emit_map_elt_val(&self, _idx: uint, f: &fn()) {
+    fn emit_map_elt_val(&mut self, _idx: uint, f: &fn(&mut PrettyEncoder)) {
         self.wr.write_str(": ");
-        f();
+        f(self);
     }
 }
 
 impl<E: serialize::Encoder> serialize::Encodable<E> for Json {
-    fn encode(&self, e: &E) {
+    fn encode(&self, e: &mut E) {
         match *self {
             Number(v) => v.encode(e),
             String(ref v) => v.encode(e),
@@ -368,7 +440,8 @@ impl<E: serialize::Encoder> serialize::Encodable<E> for Json {
 
 /// Encodes a json value into a io::writer
 pub fn to_writer(wr: @io::Writer, json: &Json) {
-    json.encode(&Encoder(wr))
+    let mut encoder = Encoder(wr);
+    json.encode(&mut encoder)
 }
 
 /// Encodes a json value into a string
@@ -378,7 +451,8 @@ pub fn to_str(json: &Json) -> ~str {
 
 /// Encodes a json value into a io::writer
 pub fn to_pretty_writer(wr: @io::Writer, json: &Json) {
-    json.encode(&PrettyEncoder(wr))
+    let mut encoder = PrettyEncoder(wr);
+    json.encode(&mut encoder)
 }
 
 /// Encodes a json value into a string
@@ -769,11 +843,13 @@ pub struct Decoder {
 }
 
 pub fn Decoder(json: Json) -> Decoder {
-    Decoder { stack: ~[json] }
+    Decoder {
+        stack: ~[json]
+    }
 }
 
 impl serialize::Decoder for Decoder {
-    fn read_nil(&self) -> () {
+    fn read_nil(&mut self) -> () {
         debug!("read_nil");
         match self.stack.pop() {
             Null => (),
@@ -781,19 +857,19 @@ impl serialize::Decoder for Decoder {
         }
     }
 
-    fn read_u64(&self)  -> u64  { self.read_float() as u64 }
-    fn read_u32(&self)  -> u32  { self.read_float() as u32 }
-    fn read_u16(&self)  -> u16  { self.read_float() as u16 }
-    fn read_u8 (&self)  -> u8   { self.read_float() as u8 }
-    fn read_uint(&self) -> uint { self.read_float() as uint }
+    fn read_u64(&mut self)  -> u64  { self.read_float() as u64 }
+    fn read_u32(&mut self)  -> u32  { self.read_float() as u32 }
+    fn read_u16(&mut self)  -> u16  { self.read_float() as u16 }
+    fn read_u8 (&mut self)  -> u8   { self.read_float() as u8 }
+    fn read_uint(&mut self) -> uint { self.read_float() as uint }
 
-    fn read_i64(&self) -> i64 { self.read_float() as i64 }
-    fn read_i32(&self) -> i32 { self.read_float() as i32 }
-    fn read_i16(&self) -> i16 { self.read_float() as i16 }
-    fn read_i8 (&self) -> i8  { self.read_float() as i8 }
-    fn read_int(&self) -> int { self.read_float() as int }
+    fn read_i64(&mut self) -> i64 { self.read_float() as i64 }
+    fn read_i32(&mut self) -> i32 { self.read_float() as i32 }
+    fn read_i16(&mut self) -> i16 { self.read_float() as i16 }
+    fn read_i8 (&mut self) -> i8  { self.read_float() as i8 }
+    fn read_int(&mut self) -> int { self.read_float() as int }
 
-    fn read_bool(&self) -> bool {
+    fn read_bool(&mut self) -> bool {
         debug!("read_bool");
         match self.stack.pop() {
             Boolean(b) => b,
@@ -801,9 +877,9 @@ impl serialize::Decoder for Decoder {
         }
     }
 
-    fn read_f64(&self) -> f64 { self.read_float() as f64 }
-    fn read_f32(&self) -> f32 { self.read_float() as f32 }
-    fn read_float(&self) -> float {
+    fn read_f64(&mut self) -> f64 { self.read_float() as f64 }
+    fn read_f32(&mut self) -> f32 { self.read_float() as f32 }
+    fn read_float(&mut self) -> float {
         debug!("read_float");
         match self.stack.pop() {
             Number(f) => f,
@@ -811,14 +887,14 @@ impl serialize::Decoder for Decoder {
         }
     }
 
-    fn read_char(&self) -> char {
+    fn read_char(&mut self) -> char {
         let mut v = ~[];
         for str::each_char(self.read_str()) |c| { v.push(c) }
         if v.len() != 1 { fail!(~"string must have one character") }
         v[0]
     }
 
-    fn read_str(&self) -> ~str {
+    fn read_str(&mut self) -> ~str {
         debug!("read_str");
         match self.stack.pop() {
             String(s) => s,
@@ -826,12 +902,15 @@ impl serialize::Decoder for Decoder {
         }
     }
 
-    fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
+    fn read_enum<T>(&mut self, name: &str, f: &fn(&mut Decoder) -> T) -> T {
         debug!("read_enum(%s)", name);
-        f()
+        f(self)
     }
 
-    fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T {
+    fn read_enum_variant<T>(&mut self,
+                            names: &[&str],
+                            f: &fn(&mut Decoder, uint) -> T)
+                            -> T {
         debug!("read_enum_variant(names=%?)", names);
         let name = match self.stack.pop() {
             String(s) => s,
@@ -850,33 +929,51 @@ impl serialize::Decoder for Decoder {
             Some(idx) => idx,
             None => fail!(fmt!("Unknown variant name: %?", name)),
         };
-        f(idx)
+        f(self, idx)
     }
 
-    fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
+    fn read_enum_variant_arg<T>(&mut self,
+                                idx: uint,
+                                f: &fn(&mut Decoder) -> T)
+                                -> T {
         debug!("read_enum_variant_arg(idx=%u)", idx);
-        f()
+        f(self)
     }
 
-    fn read_enum_struct_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T {
+    fn read_enum_struct_variant<T>(&mut self,
+                                   names: &[&str],
+                                   f: &fn(&mut Decoder, uint) -> T)
+                                   -> T {
         debug!("read_enum_struct_variant(names=%?)", names);
         self.read_enum_variant(names, f)
     }
 
 
-    fn read_enum_struct_variant_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
+    fn read_enum_struct_variant_field<T>(&mut self,
+                                         name: &str,
+                                         idx: uint,
+                                         f: &fn(&mut Decoder) -> T)
+                                         -> T {
         debug!("read_enum_struct_variant_field(name=%?, idx=%u)", name, idx);
         self.read_enum_variant_arg(idx, f)
     }
 
-    fn read_struct<T>(&self, name: &str, len: uint, f: &fn() -> T) -> T {
+    fn read_struct<T>(&mut self,
+                      name: &str,
+                      len: uint,
+                      f: &fn(&mut Decoder) -> T)
+                      -> T {
         debug!("read_struct(name=%s, len=%u)", name, len);
-        let value = f();
+        let value = f(self);
         self.stack.pop();
         value
     }
 
-    fn read_struct_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
+    fn read_struct_field<T>(&mut self,
+                            name: &str,
+                            idx: uint,
+                            f: &fn(&mut Decoder) -> T)
+                            -> T {
         debug!("read_struct_field(name=%?, idx=%u)", name, idx);
         match self.stack.pop() {
             Object(obj) => {
@@ -885,7 +982,7 @@ impl serialize::Decoder for Decoder {
                     None => fail!(fmt!("no such field: %s", name)),
                     Some(json) => {
                         self.stack.push(json);
-                        f()
+                        f(self)
                     }
                 };
                 self.stack.push(Object(obj));
@@ -895,34 +992,43 @@ impl serialize::Decoder for Decoder {
         }
     }
 
-    fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T {
+    fn read_tuple<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T {
         debug!("read_tuple()");
         self.read_seq(f)
     }
 
-    fn read_tuple_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
+    fn read_tuple_arg<T>(&mut self,
+                         idx: uint,
+                         f: &fn(&mut Decoder) -> T)
+                         -> T {
         debug!("read_tuple_arg(idx=%u)", idx);
         self.read_seq_elt(idx, f)
     }
 
-    fn read_tuple_struct<T>(&self, name: &str, f: &fn(uint) -> T) -> T {
+    fn read_tuple_struct<T>(&mut self,
+                            name: &str,
+                            f: &fn(&mut Decoder, uint) -> T)
+                            -> T {
         debug!("read_tuple_struct(name=%?)", name);
         self.read_tuple(f)
     }
 
-    fn read_tuple_struct_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
+    fn read_tuple_struct_arg<T>(&mut self,
+                                idx: uint,
+                                f: &fn(&mut Decoder) -> T)
+                                -> T {
         debug!("read_tuple_struct_arg(idx=%u)", idx);
         self.read_tuple_arg(idx, f)
     }
 
-    fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
+    fn read_option<T>(&mut self, f: &fn(&mut Decoder, bool) -> T) -> T {
         match self.stack.pop() {
-            Null => f(false),
-            value => { self.stack.push(value); f(true) }
+            Null => f(self, false),
+            value => { self.stack.push(value); f(self, true) }
         }
     }
 
-    fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
+    fn read_seq<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T {
         debug!("read_seq()");
         let len = match self.stack.pop() {
             List(list) => {
@@ -934,15 +1040,15 @@ impl serialize::Decoder for Decoder {
             }
             _ => fail!(~"not a list"),
         };
-        f(len)
+        f(self, len)
     }
 
-    fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
+    fn read_seq_elt<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T) -> T {
         debug!("read_seq_elt(idx=%u)", idx);
-        f()
+        f(self)
     }
 
-    fn read_map<T>(&self, f: &fn(uint) -> T) -> T {
+    fn read_map<T>(&mut self, f: &fn(&mut Decoder, uint) -> T) -> T {
         debug!("read_map()");
         let len = match self.stack.pop() {
             Object(obj) => {
@@ -956,17 +1062,21 @@ impl serialize::Decoder for Decoder {
             }
             json => fail!(fmt!("not an object: %?", json)),
         };
-        f(len)
+        f(self, len)
     }
 
-    fn read_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T {
+    fn read_map_elt_key<T>(&mut self,
+                           idx: uint,
+                           f: &fn(&mut Decoder) -> T)
+                           -> T {
         debug!("read_map_elt_key(idx=%u)", idx);
-        f()
+        f(self)
     }
 
-    fn read_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T {
+    fn read_map_elt_val<T>(&mut self, idx: uint, f: &fn(&mut Decoder) -> T)
+                           -> T {
         debug!("read_map_elt_val(idx=%u)", idx);
-        f()
+        f(self)
     }
 }
 
@@ -1404,15 +1514,15 @@ mod tests {
         let animal = Dog;
         assert_eq!(
             do io::with_str_writer |wr| {
-                let encoder = Encoder(wr);
-                animal.encode(&encoder);
+                let mut encoder = Encoder(wr);
+                animal.encode(&mut encoder);
             },
             ~"\"Dog\""
         );
         assert_eq!(
             do io::with_str_writer |wr| {
-                let encoder = PrettyEncoder(wr);
-                animal.encode(&encoder);
+                let mut encoder = PrettyEncoder(wr);
+                animal.encode(&mut encoder);
             },
             ~"\"Dog\""
         );
@@ -1420,15 +1530,15 @@ mod tests {
         let animal = Frog(~"Henry", 349);
         assert_eq!(
             do io::with_str_writer |wr| {
-                let encoder = Encoder(wr);
-                animal.encode(&encoder);
+                let mut encoder = Encoder(wr);
+                animal.encode(&mut encoder);
             },
             ~"[\"Frog\",\"Henry\",349]"
         );
         assert_eq!(
             do io::with_str_writer |wr| {
-                let encoder = PrettyEncoder(wr);
-                animal.encode(&encoder);
+                let mut encoder = PrettyEncoder(wr);
+                animal.encode(&mut encoder);
             },
             ~"\
             [\n  \
@@ -1443,15 +1553,15 @@ mod tests {
     fn test_write_some() {
         let value = Some(~"jodhpurs");
         let s = do io::with_str_writer |wr| {
-            let encoder = Encoder(wr);
-            value.encode(&encoder);
+            let mut encoder = Encoder(wr);
+            value.encode(&mut encoder);
         };
         assert_eq!(s, ~"\"jodhpurs\"");
 
         let value = Some(~"jodhpurs");
         let s = do io::with_str_writer |wr| {
-            let encoder = PrettyEncoder(wr);
-            value.encode(&encoder);
+            let mut encoder = PrettyEncoder(wr);
+            value.encode(&mut encoder);
         };
         assert_eq!(s, ~"\"jodhpurs\"");
     }
@@ -1460,14 +1570,14 @@ mod tests {
     fn test_write_none() {
         let value: Option<~str> = None;
         let s = do io::with_str_writer |wr| {
-            let encoder = Encoder(wr);
-            value.encode(&encoder);
+            let mut encoder = Encoder(wr);
+            value.encode(&mut encoder);
         };
         assert_eq!(s, ~"null");
 
         let s = do io::with_str_writer |wr| {
-            let encoder = Encoder(wr);
-            value.encode(&encoder);
+            let mut encoder = Encoder(wr);
+            value.encode(&mut encoder);
         };
         assert_eq!(s, ~"null");
     }
@@ -1515,13 +1625,16 @@ mod tests {
 
     #[test]
     fn test_decode_identifiers() {
-        let v: () = Decodable::decode(&Decoder(from_str(~"null").unwrap()));
+        let mut decoder = Decoder(from_str(~"null").unwrap());
+        let v: () = Decodable::decode(&mut decoder);
         assert_eq!(v, ());
 
-        let v: bool = Decodable::decode(&Decoder(from_str(~"true").unwrap()));
+        let mut decoder = Decoder(from_str(~"true").unwrap());
+        let v: bool = Decodable::decode(&mut decoder);
         assert_eq!(v, true);
 
-        let v: bool = Decodable::decode(&Decoder(from_str(~"false").unwrap()));
+        let mut decoder = Decoder(from_str(~"false").unwrap());
+        let v: bool = Decodable::decode(&mut decoder);
         assert_eq!(v, false);
     }
 
@@ -1555,25 +1668,32 @@ mod tests {
 
     #[test]
     fn test_decode_numbers() {
-        let v: float = Decodable::decode(&Decoder(from_str(~"3").unwrap()));
+        let mut decoder = Decoder(from_str(~"3").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, 3f);
 
-        let v: float = Decodable::decode(&Decoder(from_str(~"3.1").unwrap()));
+        let mut decoder = Decoder(from_str(~"3.1").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, 3.1f);
 
-        let v: float = Decodable::decode(&Decoder(from_str(~"-1.2").unwrap()));
+        let mut decoder = Decoder(from_str(~"-1.2").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, -1.2f);
 
-        let v: float = Decodable::decode(&Decoder(from_str(~"0.4").unwrap()));
+        let mut decoder = Decoder(from_str(~"0.4").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, 0.4f);
 
-        let v: float = Decodable::decode(&Decoder(from_str(~"0.4e5").unwrap()));
+        let mut decoder = Decoder(from_str(~"0.4e5").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, 0.4e5f);
 
-        let v: float = Decodable::decode(&Decoder(from_str(~"0.4e15").unwrap()));
+        let mut decoder = Decoder(from_str(~"0.4e15").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, 0.4e15f);
 
-        let v: float = Decodable::decode(&Decoder(from_str(~"0.4e-01").unwrap()));
+        let mut decoder = Decoder(from_str(~"0.4e-01").unwrap());
+        let v: float = Decodable::decode(&mut decoder);
         assert_eq!(v, 0.4e-01f);
     }
 
@@ -1600,31 +1720,40 @@ mod tests {
 
     #[test]
     fn test_decode_str() {
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"foo\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"foo\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"foo");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\\"\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\\"\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\"");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\b\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\b\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\x08");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\n\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\n\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\n");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\r\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\r\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\r");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\t\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\t\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\t");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\u12ab\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\u12ab\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\u12ab");
 
-        let v: ~str = Decodable::decode(&Decoder(from_str(~"\"\\uAB12\"").unwrap()));
+        let mut decoder = Decoder(from_str(~"\"\\uAB12\"").unwrap());
+        let v: ~str = Decodable::decode(&mut decoder);
         assert_eq!(v, ~"\uAB12");
     }
 
@@ -1656,23 +1785,28 @@ mod tests {
 
     #[test]
     fn test_decode_list() {
-        let v: ~[()] = Decodable::decode(&Decoder(from_str(~"[]").unwrap()));
+        let mut decoder = Decoder(from_str(~"[]").unwrap());
+        let v: ~[()] = Decodable::decode(&mut decoder);
         assert_eq!(v, ~[]);
 
-        let v: ~[()] = Decodable::decode(&Decoder(from_str(~"[null]").unwrap()));
+        let mut decoder = Decoder(from_str(~"[null]").unwrap());
+        let v: ~[()] = Decodable::decode(&mut decoder);
         assert_eq!(v, ~[()]);
 
-
-        let v: ~[bool] = Decodable::decode(&Decoder(from_str(~"[true]").unwrap()));
+        let mut decoder = Decoder(from_str(~"[true]").unwrap());
+        let v: ~[bool] = Decodable::decode(&mut decoder);
         assert_eq!(v, ~[true]);
 
-        let v: ~[bool] = Decodable::decode(&Decoder(from_str(~"[true]").unwrap()));
+        let mut decoder = Decoder(from_str(~"[true]").unwrap());
+        let v: ~[bool] = Decodable::decode(&mut decoder);
         assert_eq!(v, ~[true]);
 
-        let v: ~[int] = Decodable::decode(&Decoder(from_str(~"[3, 1]").unwrap()));
+        let mut decoder = Decoder(from_str(~"[3, 1]").unwrap());
+        let v: ~[int] = Decodable::decode(&mut decoder);
         assert_eq!(v, ~[3, 1]);
 
-        let v: ~[~[uint]] = Decodable::decode(&Decoder(from_str(~"[[3], [1, 2]]").unwrap()));
+        let mut decoder = Decoder(from_str(~"[[3], [1, 2]]").unwrap());
+        let v: ~[~[uint]] = Decodable::decode(&mut decoder);
         assert_eq!(v, ~[~[3], ~[1, 2]]);
     }
 
@@ -1774,7 +1908,8 @@ mod tests {
                 { \"a\": null, \"b\": 2, \"c\": [\"abc\", \"xyz\"] }
             ]
         }";
-        let v: Outer = Decodable::decode(&Decoder(from_str(s).unwrap()));
+        let mut decoder = Decoder(from_str(s).unwrap());
+        let v: Outer = Decodable::decode(&mut decoder);
         assert_eq!(
             v,
             Outer {
@@ -1787,31 +1922,32 @@ mod tests {
 
     #[test]
     fn test_decode_option() {
-        let decoder = Decoder(from_str(~"null").unwrap());
-        let value: Option<~str> = Decodable::decode(&decoder);
+        let mut decoder = Decoder(from_str(~"null").unwrap());
+        let value: Option<~str> = Decodable::decode(&mut decoder);
         assert_eq!(value, None);
 
-        let decoder = Decoder(from_str(~"\"jodhpurs\"").unwrap());
-        let value: Option<~str> = Decodable::decode(&decoder);
+        let mut decoder = Decoder(from_str(~"\"jodhpurs\"").unwrap());
+        let value: Option<~str> = Decodable::decode(&mut decoder);
         assert_eq!(value, Some(~"jodhpurs"));
     }
 
     #[test]
     fn test_decode_enum() {
-        let decoder = Decoder(from_str(~"\"Dog\"").unwrap());
-        let value: Animal = Decodable::decode(&decoder);
+        let mut decoder = Decoder(from_str(~"\"Dog\"").unwrap());
+        let value: Animal = Decodable::decode(&mut decoder);
         assert_eq!(value, Dog);
 
-        let decoder = Decoder(from_str(~"[\"Frog\",\"Henry\",349]").unwrap());
-        let value: Animal = Decodable::decode(&decoder);
+        let mut decoder =
+            Decoder(from_str(~"[\"Frog\",\"Henry\",349]").unwrap());
+        let value: Animal = Decodable::decode(&mut decoder);
         assert_eq!(value, Frog(~"Henry", 349));
     }
 
     #[test]
     fn test_decode_map() {
         let s = ~"{\"a\": \"Dog\", \"b\": [\"Frog\", \"Henry\", 349]}";
-        let decoder = Decoder(from_str(s).unwrap());
-        let mut map: HashMap<~str, Animal> = Decodable::decode(&decoder);
+        let mut decoder = Decoder(from_str(s).unwrap());
+        let mut map: HashMap<~str, Animal> = Decodable::decode(&mut decoder);
 
         assert_eq!(map.pop(&~"a"), Some(Dog));
         assert_eq!(map.pop(&~"b"), Some(Frog(~"Henry", 349)));
diff --git a/src/libstd/list.rs b/src/libstd/list.rs
index 401cc121a62..8d15508b26e 100644
--- a/src/libstd/list.rs
+++ b/src/libstd/list.rs
@@ -16,6 +16,12 @@ pub enum List<T> {
     Nil,
 }
 
+#[deriving(Eq)]
+pub enum MutList<T> {
+    MutCons(T, @mut MutList<T>),
+    MutNil,
+}
+
 /// Create a list from a vector
 pub fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
     vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
@@ -147,6 +153,25 @@ pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) {
     }
 }
 
+impl<T> MutList<T> {
+    /// Iterate over a mutable list
+    pub fn each(@mut self, f: &fn(&mut T) -> bool) {
+        let mut cur = self;
+        loop {
+            let borrowed = &mut *cur;
+            cur = match *borrowed {
+                MutCons(ref mut hd, tl) => {
+                    if !f(hd) {
+                        return;
+                    }
+                    tl
+                }
+                MutNil => break
+            }
+        }
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use list::*;
@@ -242,11 +267,3 @@ mod tests {
             == list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4])));
     }
 }
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs
index ec4c025180c..53eb6c5561b 100644
--- a/src/libstd/net_tcp.rs
+++ b/src/libstd/net_tcp.rs
@@ -11,8 +11,6 @@
 //! High-level interface to libuv's TCP functionality
 // FIXME #4425: Need FFI fixes
 
-#[allow(deprecated_mode)];
-
 use future;
 use future_spawn = future::spawn;
 use ip = net_ip;
diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs
index f3b11c13279..ba3fd69e344 100644
--- a/src/libstd/net_url.rs
+++ b/src/libstd/net_url.rs
@@ -10,18 +10,12 @@
 
 //! Types/fns concerning URLs (see RFC 3986)
 
-#[allow(deprecated_mode)];
-
 use core::cmp::Eq;
-use core::from_str::FromStr;
 use core::io::{Reader, ReaderUtil};
 use core::io;
 use core::hashmap::HashMap;
 use core::str;
-use core::to_bytes::IterBytes;
 use core::to_bytes;
-use core::to_str::ToStr;
-use core::to_str;
 use core::uint;
 
 #[deriving(Clone, Eq)]
@@ -703,13 +697,13 @@ pub fn to_str(url: &Url) -> ~str {
     fmt!("%s:%s%s%s%s", url.scheme, authority, url.path, query, fragment)
 }
 
-impl to_str::ToStr for Url {
+impl ToStr for Url {
     pub fn to_str(&self) -> ~str {
         to_str(self)
     }
 }
 
-impl to_bytes::IterBytes for Url {
+impl IterBytes for Url {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.to_str().iter_bytes(lsb0, f)
     }
diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs
index e010340b94d..cd347098e25 100644
--- a/src/libstd/num/bigint.rs
+++ b/src/libstd/num/bigint.rs
@@ -21,7 +21,6 @@ A BigInt is a combination of BigUint and Sign.
 
 use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
 use core::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix};
-use core::*;
 
 /**
 A BigDigit is a BigUint's composing element.
@@ -80,6 +79,7 @@ A big unsigned integer type.
 A BigUint-typed value BigUint { data: @[a, b, c] } represents a number
 (a + b * BigDigit::base + c * BigDigit::base^2).
 */
+#[deriving(Clone)]
 pub struct BigUint {
     priv data: ~[BigDigit]
 }
@@ -140,7 +140,7 @@ impl ToStr for BigUint {
     fn to_str(&self) -> ~str { self.to_str_radix(10) }
 }
 
-impl from_str::FromStr for BigUint {
+impl FromStr for BigUint {
     #[inline(always)]
     fn from_str(s: &str) -> Option<BigUint> {
         FromStrRadix::from_str_radix(s, 10)
@@ -293,10 +293,10 @@ impl Mul<BigUint, BigUint> for BigUint {
     }
 }
 
-impl Quot<BigUint, BigUint> for BigUint {
+impl Div<BigUint, BigUint> for BigUint {
     #[inline(always)]
-    fn quot(&self, other: &BigUint) -> BigUint {
-        let (q, _) = self.quot_rem(other);
+    fn div(&self, other: &BigUint) -> BigUint {
+        let (q, _) = self.div_rem(other);
         return q;
     }
 }
@@ -304,7 +304,7 @@ impl Quot<BigUint, BigUint> for BigUint {
 impl Rem<BigUint, BigUint> for BigUint {
     #[inline(always)]
     fn rem(&self, other: &BigUint) -> BigUint {
-        let (_, r) = self.quot_rem(other);
+        let (_, r) = self.div_rem(other);
         return r;
     }
 }
@@ -316,19 +316,24 @@ impl Neg<BigUint> for BigUint {
 
 impl Integer for BigUint {
     #[inline(always)]
-    fn div(&self, other: &BigUint) -> BigUint {
-        let (d, _) = self.div_mod(other);
+    fn div_rem(&self, other: &BigUint) -> (BigUint, BigUint) {
+        self.div_mod_floor(other)
+    }
+
+    #[inline(always)]
+    fn div_floor(&self, other: &BigUint) -> BigUint {
+        let (d, _) = self.div_mod_floor(other);
         return d;
     }
 
     #[inline(always)]
-    fn modulo(&self, other: &BigUint) -> BigUint {
-        let (_, m) = self.div_mod(other);
+    fn mod_floor(&self, other: &BigUint) -> BigUint {
+        let (_, m) = self.div_mod_floor(other);
         return m;
     }
 
     #[inline(always)]
-    fn div_mod(&self, other: &BigUint) -> (BigUint, BigUint) {
+    fn div_mod_floor(&self, other: &BigUint) -> (BigUint, BigUint) {
         if other.is_zero() { fail!() }
         if self.is_zero() { return (Zero::zero(), Zero::zero()); }
         if *other == One::one() { return (copy *self, Zero::zero()); }
@@ -346,11 +351,11 @@ impl Integer for BigUint {
             shift += 1;
         }
         assert!(shift < BigDigit::bits);
-        let (d, m) = div_mod_inner(self << shift, other << shift);
+        let (d, m) = div_mod_floor_inner(self << shift, other << shift);
         return (d, m >> shift);
 
         #[inline(always)]
-        fn div_mod_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
+        fn div_mod_floor_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
             let mut m = a;
             let mut d = Zero::zero::<BigUint>();
             let mut n = 1;
@@ -409,11 +414,6 @@ impl Integer for BigUint {
         }
     }
 
-    #[inline(always)]
-    fn quot_rem(&self, other: &BigUint) -> (BigUint, BigUint) {
-        self.div_mod(other)
-    }
-
     /**
      * Calculates the Greatest Common Divisor (GCD) of the number and `other`
      *
@@ -485,7 +485,7 @@ impl ToStrRadix for BigUint {
             let mut result = ~[];
             let mut m      = n;
             while m > divider {
-                let (d, m0) = m.div_mod(&divider);
+                let (d, m0) = m.div_mod_floor(&divider);
                 result += [m0.to_uint() as BigDigit];
                 m = d;
             }
@@ -680,7 +680,7 @@ priv fn get_radix_base(radix: uint) -> (uint, uint) {
 }
 
 /// A Sign is a BigInt's composing element.
-#[deriving(Eq)]
+#[deriving(Eq, Clone)]
 pub enum Sign { Minus, Zero, Plus }
 
 impl Ord for Sign {
@@ -726,6 +726,7 @@ impl Neg<Sign> for Sign {
 }
 
 /// A big signed integer type.
+#[deriving(Clone)]
 pub struct BigInt {
     priv sign: Sign,
     priv data: BigUint
@@ -783,7 +784,7 @@ impl ToStr for BigInt {
     fn to_str(&self) -> ~str { self.to_str_radix(10) }
 }
 
-impl from_str::FromStr for BigInt {
+impl FromStr for BigInt {
     #[inline(always)]
     fn from_str(s: &str) -> Option<BigInt> {
         FromStrRadix::from_str_radix(s, 10)
@@ -825,8 +826,8 @@ impl Signed for BigInt {
     #[inline(always)]
     fn abs(&self) -> BigInt {
         match self.sign {
-            Plus | Zero => copy *self,
-            Minus => BigInt::from_biguint(Plus, copy self.data)
+            Plus | Zero => self.clone(),
+            Minus => BigInt::from_biguint(Plus, self.data.clone())
         }
     }
 
@@ -850,8 +851,8 @@ impl Add<BigInt, BigInt> for BigInt {
     #[inline(always)]
     fn add(&self, other: &BigInt) -> BigInt {
         match (self.sign, other.sign) {
-            (Zero, _)      => copy *other,
-            (_,    Zero)   => copy *self,
+            (Zero, _)      => other.clone(),
+            (_,    Zero)   => self.clone(),
             (Plus, Plus)   => BigInt::from_biguint(Plus,
                                                    self.data + other.data),
             (Plus, Minus)  => self - (-*other),
@@ -866,7 +867,7 @@ impl Sub<BigInt, BigInt> for BigInt {
     fn sub(&self, other: &BigInt) -> BigInt {
         match (self.sign, other.sign) {
             (Zero, _)    => -other,
-            (_,    Zero) => copy *self,
+            (_,    Zero) => self.clone(),
             (Plus, Plus) => match self.data.cmp(&other.data) {
                 Less    => BigInt::from_biguint(Minus, other.data - self.data),
                 Greater => BigInt::from_biguint(Plus, self.data - other.data),
@@ -894,10 +895,10 @@ impl Mul<BigInt, BigInt> for BigInt {
     }
 }
 
-impl Quot<BigInt, BigInt> for BigInt {
+impl Div<BigInt, BigInt> for BigInt {
     #[inline(always)]
-    fn quot(&self, other: &BigInt) -> BigInt {
-        let (q, _) = self.quot_rem(other);
+    fn div(&self, other: &BigInt) -> BigInt {
+        let (q, _) = self.div_rem(other);
         return q;
     }
 }
@@ -905,7 +906,7 @@ impl Quot<BigInt, BigInt> for BigInt {
 impl Rem<BigInt, BigInt> for BigInt {
     #[inline(always)]
     fn rem(&self, other: &BigInt) -> BigInt {
-        let (_, r) = self.quot_rem(other);
+        let (_, r) = self.div_rem(other);
         return r;
     }
 }
@@ -913,27 +914,42 @@ impl Rem<BigInt, BigInt> for BigInt {
 impl Neg<BigInt> for BigInt {
     #[inline(always)]
     fn neg(&self) -> BigInt {
-        BigInt::from_biguint(self.sign.neg(), copy self.data)
+        BigInt::from_biguint(self.sign.neg(), self.data.clone())
     }
 }
 
 impl Integer for BigInt {
     #[inline(always)]
-    fn div(&self, other: &BigInt) -> BigInt {
-        let (d, _) = self.div_mod(other);
+    fn div_rem(&self, other: &BigInt) -> (BigInt, BigInt) {
+        // r.sign == self.sign
+        let (d_ui, r_ui) = self.data.div_mod_floor(&other.data);
+        let d = BigInt::from_biguint(Plus, d_ui);
+        let r = BigInt::from_biguint(Plus, r_ui);
+        match (self.sign, other.sign) {
+            (_,    Zero)   => fail!(),
+            (Plus, Plus)  | (Zero, Plus)  => ( d,  r),
+            (Plus, Minus) | (Zero, Minus) => (-d,  r),
+            (Minus, Plus)                 => (-d, -r),
+            (Minus, Minus)                => ( d, -r)
+        }
+    }
+
+    #[inline(always)]
+    fn div_floor(&self, other: &BigInt) -> BigInt {
+        let (d, _) = self.div_mod_floor(other);
         return d;
     }
 
     #[inline(always)]
-    fn modulo(&self, other: &BigInt) -> BigInt {
-        let (_, m) = self.div_mod(other);
+    fn mod_floor(&self, other: &BigInt) -> BigInt {
+        let (_, m) = self.div_mod_floor(other);
         return m;
     }
 
     #[inline(always)]
-    fn div_mod(&self, other: &BigInt) -> (BigInt, BigInt) {
+    fn div_mod_floor(&self, other: &BigInt) -> (BigInt, BigInt) {
         // m.sign == other.sign
-        let (d_ui, m_ui) = self.data.quot_rem(&other.data);
+        let (d_ui, m_ui) = self.data.div_rem(&other.data);
         let d = BigInt::from_biguint(Plus, d_ui),
             m = BigInt::from_biguint(Plus, m_ui);
         match (self.sign, other.sign) {
@@ -953,21 +969,6 @@ impl Integer for BigInt {
         }
     }
 
-    #[inline(always)]
-    fn quot_rem(&self, other: &BigInt) -> (BigInt, BigInt) {
-        // r.sign == self.sign
-        let (q_ui, r_ui) = self.data.div_mod(&other.data);
-        let q = BigInt::from_biguint(Plus, q_ui);
-        let r = BigInt::from_biguint(Plus, r_ui);
-        match (self.sign, other.sign) {
-            (_,    Zero)   => fail!(),
-            (Plus, Plus)  | (Zero, Plus)  => ( q,  r),
-            (Plus, Minus) | (Zero, Minus) => (-q,  r),
-            (Minus, Plus)                 => (-q, -r),
-            (Minus, Minus)                => ( q, -r)
-        }
-    }
-
     /**
      * Calculates the Greatest Common Divisor (GCD) of the number and `other`
      *
@@ -1100,11 +1101,9 @@ pub impl BigInt {
 
 #[cfg(test)]
 mod biguint_tests {
-
-    use core::*;
+    use super::*;
     use core::num::{IntConvertible, Zero, One, FromStrRadix};
     use core::cmp::{Less, Equal, Greater};
-    use super::{BigUint, BigDigit};
 
     #[test]
     fn test_from_slice() {
@@ -1347,7 +1346,7 @@ mod biguint_tests {
         (&[ 0,  0,  1],     &[ 0,  0,  0,  1], &[0, 0,  0,  0,  0,  1])
     ];
 
-    static quot_rem_quadruples: &'static [(&'static [BigDigit],
+    static div_rem_quadruples: &'static [(&'static [BigDigit],
                                            &'static [BigDigit],
                                            &'static [BigDigit],
                                            &'static [BigDigit])]
@@ -1371,7 +1370,7 @@ mod biguint_tests {
             assert!(b * a == c);
         }
 
-        for quot_rem_quadruples.each |elm| {
+        for div_rem_quadruples.each |elm| {
             let (aVec, bVec, cVec, dVec) = *elm;
             let a = BigUint::from_slice(aVec);
             let b = BigUint::from_slice(bVec);
@@ -1384,7 +1383,7 @@ mod biguint_tests {
     }
 
     #[test]
-    fn test_quot_rem() {
+    fn test_div_rem() {
         for mul_triples.each |elm| {
             let (aVec, bVec, cVec) = *elm;
             let a = BigUint::from_slice(aVec);
@@ -1392,21 +1391,21 @@ mod biguint_tests {
             let c = BigUint::from_slice(cVec);
 
             if !a.is_zero() {
-                assert!(c.quot_rem(&a) == (copy b, Zero::zero()));
+                assert!(c.div_rem(&a) == (b.clone(), Zero::zero()));
             }
             if !b.is_zero() {
-                assert!(c.quot_rem(&b) == (copy a, Zero::zero()));
+                assert!(c.div_rem(&b) == (a.clone(), Zero::zero()));
             }
         }
 
-        for quot_rem_quadruples.each |elm| {
+        for div_rem_quadruples.each |elm| {
             let (aVec, bVec, cVec, dVec) = *elm;
             let a = BigUint::from_slice(aVec);
             let b = BigUint::from_slice(bVec);
             let c = BigUint::from_slice(cVec);
             let d = BigUint::from_slice(dVec);
 
-            if !b.is_zero() { assert!(a.quot_rem(&b) == (c, d)); }
+            if !b.is_zero() { assert!(a.div_rem(&b) == (c, d)); }
         }
     }
 
@@ -1557,8 +1556,7 @@ mod biguint_tests {
 
 #[cfg(test)]
 mod bigint_tests {
-    use super::{BigInt, BigUint, BigDigit, Sign, Minus, Zero, Plus};
-    use core::*;
+    use super::*;
     use core::cmp::{Less, Equal, Greater};
     use core::num::{IntConvertible, Zero, One, FromStrRadix};
 
@@ -1750,10 +1748,10 @@ mod bigint_tests {
         (&[ 0,  0,  1],     &[ 0,  0,  0,  1], &[0, 0,  0,  0,  0,  1])
     ];
 
-    static quot_rem_quadruples: &'static [(&'static [BigDigit],
-                                           &'static [BigDigit],
-                                           &'static [BigDigit],
-                                           &'static [BigDigit])]
+    static div_rem_quadruples: &'static [(&'static [BigDigit],
+                                          &'static [BigDigit],
+                                          &'static [BigDigit],
+                                          &'static [BigDigit])]
         = &[
             (&[ 1],        &[ 2], &[],               &[1]),
             (&[ 1,  1],    &[ 2], &[-1/2+1],         &[1]),
@@ -1777,7 +1775,7 @@ mod bigint_tests {
             assert!((-b) * a == -c);
         }
 
-        for quot_rem_quadruples.each |elm| {
+        for div_rem_quadruples.each |elm| {
             let (aVec, bVec, cVec, dVec) = *elm;
             let a = BigInt::from_slice(Plus, aVec);
             let b = BigInt::from_slice(Plus, bVec);
@@ -1790,9 +1788,9 @@ mod bigint_tests {
     }
 
     #[test]
-    fn test_div_mod() {
+    fn test_div_mod_floor() {
         fn check_sub(a: &BigInt, b: &BigInt, ans_d: &BigInt, ans_m: &BigInt) {
-            let (d, m) = a.div_mod(b);
+            let (d, m) = a.div_mod_floor(b);
             if !m.is_zero() {
                 assert!(m.sign == b.sign);
             }
@@ -1826,7 +1824,7 @@ mod bigint_tests {
             if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
         }
 
-        for quot_rem_quadruples.each |elm| {
+        for div_rem_quadruples.each |elm| {
             let (aVec, bVec, cVec, dVec) = *elm;
             let a = BigInt::from_slice(Plus, aVec);
             let b = BigInt::from_slice(Plus, bVec);
@@ -1841,9 +1839,9 @@ mod bigint_tests {
 
 
     #[test]
-    fn test_quot_rem() {
+    fn test_div_rem() {
         fn check_sub(a: &BigInt, b: &BigInt, ans_q: &BigInt, ans_r: &BigInt) {
-            let (q, r) = a.quot_rem(b);
+            let (q, r) = a.div_rem(b);
             if !r.is_zero() {
                 assert!(r.sign == a.sign);
             }
@@ -1869,7 +1867,7 @@ mod bigint_tests {
             if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
         }
 
-        for quot_rem_quadruples.each |elm| {
+        for div_rem_quadruples.each |elm| {
             let (aVec, bVec, cVec, dVec) = *elm;
             let a = BigInt::from_slice(Plus, aVec);
             let b = BigInt::from_slice(Plus, bVec);
@@ -1959,4 +1957,3 @@ mod bigint_tests {
         assert!(-Zero::zero::<BigInt>() == Zero::zero::<BigInt>());
     }
 }
-
diff --git a/src/libstd/num/complex.rs b/src/libstd/num/complex.rs
index 02393b15cca..41d2b4a101c 100644
--- a/src/libstd/num/complex.rs
+++ b/src/libstd/num/complex.rs
@@ -102,9 +102,9 @@ impl<T: Copy + Num> Mul<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
 
 // (a + i b) / (c + i d) == [(a + i b) * (c - i d)] / (c*c + d*d)
 //   == [(a*c + b*d) / (c*c + d*d)] + i [(b*c - a*d) / (c*c + d*d)]
-impl<T: Copy + Num> Quot<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
+impl<T: Copy + Num> Div<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
     #[inline]
-    fn quot(&self, other: &Cmplx<T>) -> Cmplx<T> {
+    fn div(&self, other: &Cmplx<T>) -> Cmplx<T> {
         let norm_sqr = other.norm_sqr();
         Cmplx::new((self.re*other.re + self.im*other.im) / norm_sqr,
                      (self.im*other.re - self.re*other.im) / norm_sqr)
@@ -275,7 +275,7 @@ mod test {
             }
         }
         #[test]
-        fn test_quot() {
+        fn test_div() {
             assert_eq!(_neg1_1i / _0_1i, _1_1i);
             for all_consts.each |&c| {
                 if c != Zero::zero() {
diff --git a/src/libstd/num/rational.rs b/src/libstd/num/rational.rs
index a7c170c1cd6..9b92b7241b9 100644
--- a/src/libstd/num/rational.rs
+++ b/src/libstd/num/rational.rs
@@ -143,9 +143,9 @@ impl<T: Copy + Num + Ord>
 
 // (a/b) / (c/d) = (a*d)/(b*c)
 impl<T: Copy + Num + Ord>
-    Quot<Ratio<T>,Ratio<T>> for Ratio<T> {
+    Div<Ratio<T>,Ratio<T>> for Ratio<T> {
     #[inline]
-    fn quot(&self, rhs: &Ratio<T>) -> Ratio<T> {
+    fn div(&self, rhs: &Ratio<T>) -> Ratio<T> {
         Ratio::new(self.numer * rhs.denom, self.denom * rhs.numer)
     }
 }
@@ -395,7 +395,7 @@ mod test {
         }
 
         #[test]
-        fn test_quot() {
+        fn test_div() {
             assert_eq!(_1 / _1_2, _2);
             assert_eq!(_3_2 / _1_2, _1 + _2);
             assert_eq!(_1 / _neg1_2, _neg1_2 + _neg1_2 + _neg1_2 + _neg1_2);
@@ -424,7 +424,7 @@ mod test {
         }
         #[test]
         #[should_fail]
-        fn test_quot_0() {
+        fn test_div_0() {
             let _a =  _1 / _0;
         }
     }
diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs
index 29d108e3ac2..a5d2604b6f6 100644
--- a/src/libstd/serialize.rs
+++ b/src/libstd/serialize.rs
@@ -24,377 +24,457 @@ use treemap::{TreeMap, TreeSet};
 
 pub trait Encoder {
     // Primitive types:
-    fn emit_nil(&self);
-    fn emit_uint(&self, v: uint);
-    fn emit_u64(&self, v: u64);
-    fn emit_u32(&self, v: u32);
-    fn emit_u16(&self, v: u16);
-    fn emit_u8(&self, v: u8);
-    fn emit_int(&self, v: int);
-    fn emit_i64(&self, v: i64);
-    fn emit_i32(&self, v: i32);
-    fn emit_i16(&self, v: i16);
-    fn emit_i8(&self, v: i8);
-    fn emit_bool(&self, v: bool);
-    fn emit_float(&self, v: float);
-    fn emit_f64(&self, v: f64);
-    fn emit_f32(&self, v: f32);
-    fn emit_char(&self, v: char);
-    fn emit_str(&self, v: &str);
+    fn emit_nil(&mut self);
+    fn emit_uint(&mut self, v: uint);
+    fn emit_u64(&mut self, v: u64);
+    fn emit_u32(&mut self, v: u32);
+    fn emit_u16(&mut self, v: u16);
+    fn emit_u8(&mut self, v: u8);
+    fn emit_int(&mut self, v: int);
+    fn emit_i64(&mut self, v: i64);
+    fn emit_i32(&mut self, v: i32);
+    fn emit_i16(&mut self, v: i16);
+    fn emit_i8(&mut self, v: i8);
+    fn emit_bool(&mut self, v: bool);
+    fn emit_float(&mut self, v: float);
+    fn emit_f64(&mut self, v: f64);
+    fn emit_f32(&mut self, v: f32);
+    fn emit_char(&mut self, v: char);
+    fn emit_str(&mut self, v: &str);
 
     // Compound types:
-    fn emit_enum(&self, name: &str, f: &fn());
-
-    fn emit_enum_variant(&self, v_name: &str, v_id: uint, len: uint, f: &fn());
-    fn emit_enum_variant_arg(&self, a_idx: uint, f: &fn());
-
-    fn emit_enum_struct_variant(&self, v_name: &str, v_id: uint, len: uint, f: &fn());
-    fn emit_enum_struct_variant_field(&self, f_name: &str, f_idx: uint, f: &fn());
-
-    fn emit_struct(&self, name: &str, len: uint, f: &fn());
-    fn emit_struct_field(&self, f_name: &str, f_idx: uint, f: &fn());
-
-    fn emit_tuple(&self, len: uint, f: &fn());
-    fn emit_tuple_arg(&self, idx: uint, f: &fn());
-
-    fn emit_tuple_struct(&self, name: &str, len: uint, f: &fn());
-    fn emit_tuple_struct_arg(&self, f_idx: uint, f: &fn());
+    fn emit_enum(&mut self, name: &str, f: &fn(&mut Self));
+
+    fn emit_enum_variant(&mut self,
+                         v_name: &str,
+                         v_id: uint,
+                         len: uint,
+                         f: &fn(&mut Self));
+    fn emit_enum_variant_arg(&mut self, a_idx: uint, f: &fn(&mut Self));
+
+    fn emit_enum_struct_variant(&mut self,
+                                v_name: &str,
+                                v_id: uint,
+                                len: uint,
+                                f: &fn(&mut Self));
+    fn emit_enum_struct_variant_field(&mut self,
+                                      f_name: &str,
+                                      f_idx: uint,
+                                      f: &fn(&mut Self));
+
+    fn emit_struct(&mut self, name: &str, len: uint, f: &fn(&mut Self));
+    fn emit_struct_field(&mut self,
+                         f_name: &str,
+                         f_idx: uint,
+                         f: &fn(&mut Self));
+
+    fn emit_tuple(&mut self, len: uint, f: &fn(&mut Self));
+    fn emit_tuple_arg(&mut self, idx: uint, f: &fn(&mut Self));
+
+    fn emit_tuple_struct(&mut self, name: &str, len: uint, f: &fn(&mut Self));
+    fn emit_tuple_struct_arg(&mut self, f_idx: uint, f: &fn(&mut Self));
 
     // Specialized types:
-    fn emit_option(&self, f: &fn());
-    fn emit_option_none(&self);
-    fn emit_option_some(&self, f: &fn());
+    fn emit_option(&mut self, f: &fn(&mut Self));
+    fn emit_option_none(&mut self);
+    fn emit_option_some(&mut self, f: &fn(&mut Self));
 
-    fn emit_seq(&self, len: uint, f: &fn());
-    fn emit_seq_elt(&self, idx: uint, f: &fn());
+    fn emit_seq(&mut self, len: uint, f: &fn(this: &mut Self));
+    fn emit_seq_elt(&mut self, idx: uint, f: &fn(this: &mut Self));
 
-    fn emit_map(&self, len: uint, f: &fn());
-    fn emit_map_elt_key(&self, idx: uint, f: &fn());
-    fn emit_map_elt_val(&self, idx: uint, f: &fn());
+    fn emit_map(&mut self, len: uint, f: &fn(&mut Self));
+    fn emit_map_elt_key(&mut self, idx: uint, f: &fn(&mut Self));
+    fn emit_map_elt_val(&mut self, idx: uint, f: &fn(&mut Self));
 }
 
 pub trait Decoder {
     // Primitive types:
-    fn read_nil(&self) -> ();
-    fn read_uint(&self) -> uint;
-    fn read_u64(&self) -> u64;
-    fn read_u32(&self) -> u32;
-    fn read_u16(&self) -> u16;
-    fn read_u8(&self) -> u8;
-    fn read_int(&self) -> int;
-    fn read_i64(&self) -> i64;
-    fn read_i32(&self) -> i32;
-    fn read_i16(&self) -> i16;
-    fn read_i8(&self) -> i8;
-    fn read_bool(&self) -> bool;
-    fn read_f64(&self) -> f64;
-    fn read_f32(&self) -> f32;
-    fn read_float(&self) -> float;
-    fn read_char(&self) -> char;
-    fn read_str(&self) -> ~str;
+    fn read_nil(&mut self) -> ();
+    fn read_uint(&mut self) -> uint;
+    fn read_u64(&mut self) -> u64;
+    fn read_u32(&mut self) -> u32;
+    fn read_u16(&mut self) -> u16;
+    fn read_u8(&mut self) -> u8;
+    fn read_int(&mut self) -> int;
+    fn read_i64(&mut self) -> i64;
+    fn read_i32(&mut self) -> i32;
+    fn read_i16(&mut self) -> i16;
+    fn read_i8(&mut self) -> i8;
+    fn read_bool(&mut self) -> bool;
+    fn read_f64(&mut self) -> f64;
+    fn read_f32(&mut self) -> f32;
+    fn read_float(&mut self) -> float;
+    fn read_char(&mut self) -> char;
+    fn read_str(&mut self) -> ~str;
 
     // Compound types:
-    fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T;
-
-    fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
-    fn read_enum_variant_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T;
-
-    fn read_enum_struct_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
-    fn read_enum_struct_variant_field<T>(&self, &f_name: &str, f_idx: uint, f: &fn() -> T) -> T;
-
-    fn read_struct<T>(&self, s_name: &str, len: uint, f: &fn() -> T) -> T;
-    fn read_struct_field<T>(&self, f_name: &str, f_idx: uint, f: &fn() -> T) -> T;
-
-    fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T;
-    fn read_tuple_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T;
-
-    fn read_tuple_struct<T>(&self, s_name: &str, f: &fn(uint) -> T) -> T;
-    fn read_tuple_struct_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T;
+    fn read_enum<T>(&mut self, name: &str, f: &fn(&mut Self) -> T) -> T;
+
+    fn read_enum_variant<T>(&mut self,
+                            names: &[&str],
+                            f: &fn(&mut Self, uint) -> T)
+                            -> T;
+    fn read_enum_variant_arg<T>(&mut self,
+                                a_idx: uint,
+                                f: &fn(&mut Self) -> T)
+                                -> T;
+
+    fn read_enum_struct_variant<T>(&mut self,
+                                   names: &[&str],
+                                   f: &fn(&mut Self, uint) -> T)
+                                   -> T;
+    fn read_enum_struct_variant_field<T>(&mut self,
+                                         &f_name: &str,
+                                         f_idx: uint,
+                                         f: &fn(&mut Self) -> T)
+                                         -> T;
+
+    fn read_struct<T>(&mut self,
+                      s_name: &str,
+                      len: uint,
+                      f: &fn(&mut Self) -> T)
+                      -> T;
+    fn read_struct_field<T>(&mut self,
+                            f_name: &str,
+                            f_idx: uint,
+                            f: &fn(&mut Self) -> T)
+                            -> T;
+
+    fn read_tuple<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T;
+    fn read_tuple_arg<T>(&mut self, a_idx: uint, f: &fn(&mut Self) -> T) -> T;
+
+    fn read_tuple_struct<T>(&mut self,
+                            s_name: &str,
+                            f: &fn(&mut Self, uint) -> T)
+                            -> T;
+    fn read_tuple_struct_arg<T>(&mut self,
+                                a_idx: uint,
+                                f: &fn(&mut Self) -> T)
+                                -> T;
 
     // Specialized types:
-    fn read_option<T>(&self, f: &fn(bool) -> T) -> T;
+    fn read_option<T>(&mut self, f: &fn(&mut Self, bool) -> T) -> T;
 
-    fn read_seq<T>(&self, f: &fn(uint) -> T) -> T;
-    fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T;
+    fn read_seq<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T;
+    fn read_seq_elt<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T;
 
-    fn read_map<T>(&self, f: &fn(uint) -> T) -> T;
-    fn read_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T;
-    fn read_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T;
+    fn read_map<T>(&mut self, f: &fn(&mut Self, uint) -> T) -> T;
+    fn read_map_elt_key<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T;
+    fn read_map_elt_val<T>(&mut self, idx: uint, f: &fn(&mut Self) -> T) -> T;
 }
 
 pub trait Encodable<S:Encoder> {
-    fn encode(&self, s: &S);
+    fn encode(&self, s: &mut S);
 }
 
 pub trait Decodable<D:Decoder> {
-    fn decode(d: &D) -> Self;
+    fn decode(d: &mut D) -> Self;
 }
 
 impl<S:Encoder> Encodable<S> for uint {
-    fn encode(&self, s: &S) { s.emit_uint(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_uint(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for uint {
-    fn decode(d: &D) -> uint {
+    fn decode(d: &mut D) -> uint {
         d.read_uint()
     }
 }
 
 impl<S:Encoder> Encodable<S> for u8 {
-    fn encode(&self, s: &S) { s.emit_u8(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_u8(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for u8 {
-    fn decode(d: &D) -> u8 {
+    fn decode(d: &mut D) -> u8 {
         d.read_u8()
     }
 }
 
 impl<S:Encoder> Encodable<S> for u16 {
-    fn encode(&self, s: &S) { s.emit_u16(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_u16(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for u16 {
-    fn decode(d: &D) -> u16 {
+    fn decode(d: &mut D) -> u16 {
         d.read_u16()
     }
 }
 
 impl<S:Encoder> Encodable<S> for u32 {
-    fn encode(&self, s: &S) { s.emit_u32(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_u32(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for u32 {
-    fn decode(d: &D) -> u32 {
+    fn decode(d: &mut D) -> u32 {
         d.read_u32()
     }
 }
 
 impl<S:Encoder> Encodable<S> for u64 {
-    fn encode(&self, s: &S) { s.emit_u64(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_u64(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for u64 {
-    fn decode(d: &D) -> u64 {
+    fn decode(d: &mut D) -> u64 {
         d.read_u64()
     }
 }
 
 impl<S:Encoder> Encodable<S> for int {
-    fn encode(&self, s: &S) { s.emit_int(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_int(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for int {
-    fn decode(d: &D) -> int {
+    fn decode(d: &mut D) -> int {
         d.read_int()
     }
 }
 
 impl<S:Encoder> Encodable<S> for i8 {
-    fn encode(&self, s: &S) { s.emit_i8(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_i8(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for i8 {
-    fn decode(d: &D) -> i8 {
+    fn decode(d: &mut D) -> i8 {
         d.read_i8()
     }
 }
 
 impl<S:Encoder> Encodable<S> for i16 {
-    fn encode(&self, s: &S) { s.emit_i16(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_i16(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for i16 {
-    fn decode(d: &D) -> i16 {
+    fn decode(d: &mut D) -> i16 {
         d.read_i16()
     }
 }
 
 impl<S:Encoder> Encodable<S> for i32 {
-    fn encode(&self, s: &S) { s.emit_i32(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_i32(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for i32 {
-    fn decode(d: &D) -> i32 {
+    fn decode(d: &mut D) -> i32 {
         d.read_i32()
     }
 }
 
 impl<S:Encoder> Encodable<S> for i64 {
-    fn encode(&self, s: &S) { s.emit_i64(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_i64(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for i64 {
-    fn decode(d: &D) -> i64 {
+    fn decode(d: &mut D) -> i64 {
         d.read_i64()
     }
 }
 
 impl<'self, S:Encoder> Encodable<S> for &'self str {
-    fn encode(&self, s: &S) { s.emit_str(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_str(*self)
+    }
 }
 
 impl<S:Encoder> Encodable<S> for ~str {
-    fn encode(&self, s: &S) { s.emit_str(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_str(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for ~str {
-    fn decode(d: &D) -> ~str {
+    fn decode(d: &mut D) -> ~str {
         d.read_str()
     }
 }
 
 impl<S:Encoder> Encodable<S> for @str {
-    fn encode(&self, s: &S) { s.emit_str(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_str(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for @str {
-    fn decode(d: &D) -> @str { d.read_str().to_managed() }
+    fn decode(d: &mut D) -> @str {
+        d.read_str().to_managed()
+    }
 }
 
 impl<S:Encoder> Encodable<S> for float {
-    fn encode(&self, s: &S) { s.emit_float(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_float(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for float {
-    fn decode(d: &D) -> float {
+    fn decode(d: &mut D) -> float {
         d.read_float()
     }
 }
 
 impl<S:Encoder> Encodable<S> for f32 {
-    fn encode(&self, s: &S) { s.emit_f32(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_f32(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for f32 {
-    fn decode(d: &D) -> f32 {
-        d.read_f32() }
+    fn decode(d: &mut D) -> f32 {
+        d.read_f32()
+    }
 }
 
 impl<S:Encoder> Encodable<S> for f64 {
-    fn encode(&self, s: &S) { s.emit_f64(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_f64(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for f64 {
-    fn decode(d: &D) -> f64 {
+    fn decode(d: &mut D) -> f64 {
         d.read_f64()
     }
 }
 
 impl<S:Encoder> Encodable<S> for bool {
-    fn encode(&self, s: &S) { s.emit_bool(*self) }
+    fn encode(&self, s: &mut S) {
+        s.emit_bool(*self)
+    }
 }
 
 impl<D:Decoder> Decodable<D> for bool {
-    fn decode(d: &D) -> bool {
+    fn decode(d: &mut D) -> bool {
         d.read_bool()
     }
 }
 
 impl<S:Encoder> Encodable<S> for () {
-    fn encode(&self, s: &S) { s.emit_nil() }
+    fn encode(&self, s: &mut S) {
+        s.emit_nil()
+    }
 }
 
 impl<D:Decoder> Decodable<D> for () {
-    fn decode(d: &D) -> () {
+    fn decode(d: &mut D) -> () {
         d.read_nil()
     }
 }
 
 impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self T {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         (**self).encode(s)
     }
 }
 
 impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~T {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         (**self).encode(s)
     }
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~T {
-    fn decode(d: &D) -> ~T {
+    fn decode(d: &mut D) -> ~T {
         ~Decodable::decode(d)
     }
 }
 
 impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         (**self).encode(s)
     }
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T {
-    fn decode(d: &D) -> @T {
+    fn decode(d: &mut D) -> @T {
         @Decodable::decode(d)
     }
 }
 
 impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             for self.eachi |i, e| {
-                s.emit_seq_elt(i, || e.encode(s))
+                s.emit_seq_elt(i, |s| e.encode(s))
             }
         }
     }
 }
 
 impl<S:Encoder,T:Encodable<S>> Encodable<S> for ~[T] {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             for self.eachi |i, e| {
-                s.emit_seq_elt(i, || e.encode(s))
+                s.emit_seq_elt(i, |s| e.encode(s))
             }
         }
     }
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for ~[T] {
-    fn decode(d: &D) -> ~[T] {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> ~[T] {
+        do d.read_seq |d, len| {
             do vec::from_fn(len) |i| {
-                d.read_seq_elt(i, || Decodable::decode(d))
+                d.read_seq_elt(i, |d| Decodable::decode(d))
             }
         }
     }
 }
 
 impl<S:Encoder,T:Encodable<S>> Encodable<S> for @[T] {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             for self.eachi |i, e| {
-                s.emit_seq_elt(i, || e.encode(s))
+                s.emit_seq_elt(i, |s| e.encode(s))
             }
         }
     }
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for @[T] {
-    fn decode(d: &D) -> @[T] {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> @[T] {
+        do d.read_seq |d, len| {
             do at_vec::from_fn(len) |i| {
-                d.read_seq_elt(i, || Decodable::decode(d))
+                d.read_seq_elt(i, |d| Decodable::decode(d))
             }
         }
     }
 }
 
 impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> {
-    fn encode(&self, s: &S) {
-        do s.emit_option {
+    fn encode(&self, s: &mut S) {
+        do s.emit_option |s| {
             match *self {
                 None => s.emit_option_none(),
-                Some(ref v) => s.emit_option_some(|| v.encode(s)),
+                Some(ref v) => s.emit_option_some(|s| v.encode(s)),
             }
         }
     }
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> {
-    fn decode(d: &D) -> Option<T> {
-        do d.read_option |b| {
+    fn decode(d: &mut D) -> Option<T> {
+        do d.read_option |d, b| {
             if b {
                 Some(Decodable::decode(d))
             } else {
@@ -405,12 +485,12 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for Option<T> {
 }
 
 impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S> for (T0, T1) {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         match *self {
             (ref t0, ref t1) => {
-                do s.emit_seq(2) {
-                    s.emit_seq_elt(0, || t0.encode(s));
-                    s.emit_seq_elt(1, || t1.encode(s));
+                do s.emit_seq(2) |s| {
+                    s.emit_seq_elt(0, |s| t0.encode(s));
+                    s.emit_seq_elt(1, |s| t1.encode(s));
                 }
             }
         }
@@ -418,12 +498,12 @@ impl<S:Encoder,T0:Encodable<S>,T1:Encodable<S>> Encodable<S> for (T0, T1) {
 }
 
 impl<D:Decoder,T0:Decodable<D>,T1:Decodable<D>> Decodable<D> for (T0, T1) {
-    fn decode(d: &D) -> (T0, T1) {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> (T0, T1) {
+        do d.read_seq |d, len| {
             assert!(len == 2);
             (
-                d.read_seq_elt(0, || Decodable::decode(d)),
-                d.read_seq_elt(1, || Decodable::decode(d))
+                d.read_seq_elt(0, |d| Decodable::decode(d)),
+                d.read_seq_elt(1, |d| Decodable::decode(d))
             )
         }
     }
@@ -435,13 +515,13 @@ impl<
     T1: Encodable<S>,
     T2: Encodable<S>
 > Encodable<S> for (T0, T1, T2) {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         match *self {
             (ref t0, ref t1, ref t2) => {
-                do s.emit_seq(3) {
-                    s.emit_seq_elt(0, || t0.encode(s));
-                    s.emit_seq_elt(1, || t1.encode(s));
-                    s.emit_seq_elt(2, || t2.encode(s));
+                do s.emit_seq(3) |s| {
+                    s.emit_seq_elt(0, |s| t0.encode(s));
+                    s.emit_seq_elt(1, |s| t1.encode(s));
+                    s.emit_seq_elt(2, |s| t2.encode(s));
                 }
             }
         }
@@ -454,13 +534,13 @@ impl<
     T1: Decodable<D>,
     T2: Decodable<D>
 > Decodable<D> for (T0, T1, T2) {
-    fn decode(d: &D) -> (T0, T1, T2) {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> (T0, T1, T2) {
+        do d.read_seq |d, len| {
             assert!(len == 3);
             (
-                d.read_seq_elt(0, || Decodable::decode(d)),
-                d.read_seq_elt(1, || Decodable::decode(d)),
-                d.read_seq_elt(2, || Decodable::decode(d))
+                d.read_seq_elt(0, |d| Decodable::decode(d)),
+                d.read_seq_elt(1, |d| Decodable::decode(d)),
+                d.read_seq_elt(2, |d| Decodable::decode(d))
             )
         }
     }
@@ -473,14 +553,14 @@ impl<
     T2: Encodable<S>,
     T3: Encodable<S>
 > Encodable<S> for (T0, T1, T2, T3) {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         match *self {
             (ref t0, ref t1, ref t2, ref t3) => {
-                do s.emit_seq(4) {
-                    s.emit_seq_elt(0, || t0.encode(s));
-                    s.emit_seq_elt(1, || t1.encode(s));
-                    s.emit_seq_elt(2, || t2.encode(s));
-                    s.emit_seq_elt(3, || t3.encode(s));
+                do s.emit_seq(4) |s| {
+                    s.emit_seq_elt(0, |s| t0.encode(s));
+                    s.emit_seq_elt(1, |s| t1.encode(s));
+                    s.emit_seq_elt(2, |s| t2.encode(s));
+                    s.emit_seq_elt(3, |s| t3.encode(s));
                 }
             }
         }
@@ -494,14 +574,14 @@ impl<
     T2: Decodable<D>,
     T3: Decodable<D>
 > Decodable<D> for (T0, T1, T2, T3) {
-    fn decode(d: &D) -> (T0, T1, T2, T3) {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> (T0, T1, T2, T3) {
+        do d.read_seq |d, len| {
             assert!(len == 4);
             (
-                d.read_seq_elt(0, || Decodable::decode(d)),
-                d.read_seq_elt(1, || Decodable::decode(d)),
-                d.read_seq_elt(2, || Decodable::decode(d)),
-                d.read_seq_elt(3, || Decodable::decode(d))
+                d.read_seq_elt(0, |d| Decodable::decode(d)),
+                d.read_seq_elt(1, |d| Decodable::decode(d)),
+                d.read_seq_elt(2, |d| Decodable::decode(d)),
+                d.read_seq_elt(3, |d| Decodable::decode(d))
             )
         }
     }
@@ -515,15 +595,15 @@ impl<
     T3: Encodable<S>,
     T4: Encodable<S>
 > Encodable<S> for (T0, T1, T2, T3, T4) {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         match *self {
             (ref t0, ref t1, ref t2, ref t3, ref t4) => {
-                do s.emit_seq(5) {
-                    s.emit_seq_elt(0, || t0.encode(s));
-                    s.emit_seq_elt(1, || t1.encode(s));
-                    s.emit_seq_elt(2, || t2.encode(s));
-                    s.emit_seq_elt(3, || t3.encode(s));
-                    s.emit_seq_elt(4, || t4.encode(s));
+                do s.emit_seq(5) |s| {
+                    s.emit_seq_elt(0, |s| t0.encode(s));
+                    s.emit_seq_elt(1, |s| t1.encode(s));
+                    s.emit_seq_elt(2, |s| t2.encode(s));
+                    s.emit_seq_elt(3, |s| t3.encode(s));
+                    s.emit_seq_elt(4, |s| t4.encode(s));
                 }
             }
         }
@@ -538,16 +618,15 @@ impl<
     T3: Decodable<D>,
     T4: Decodable<D>
 > Decodable<D> for (T0, T1, T2, T3, T4) {
-    fn decode(d: &D)
-      -> (T0, T1, T2, T3, T4) {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> (T0, T1, T2, T3, T4) {
+        do d.read_seq |d, len| {
             assert!(len == 5);
             (
-                d.read_seq_elt(0, || Decodable::decode(d)),
-                d.read_seq_elt(1, || Decodable::decode(d)),
-                d.read_seq_elt(2, || Decodable::decode(d)),
-                d.read_seq_elt(3, || Decodable::decode(d)),
-                d.read_seq_elt(4, || Decodable::decode(d))
+                d.read_seq_elt(0, |d| Decodable::decode(d)),
+                d.read_seq_elt(1, |d| Decodable::decode(d)),
+                d.read_seq_elt(2, |d| Decodable::decode(d)),
+                d.read_seq_elt(3, |d| Decodable::decode(d)),
+                d.read_seq_elt(4, |d| Decodable::decode(d))
             )
         }
     }
@@ -557,11 +636,11 @@ impl<
     S: Encoder,
     T: Encodable<S> + Copy
 > Encodable<S> for @mut DList<T> {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.size) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.size) |s| {
             let mut i = 0;
             for self.each |e| {
-                s.emit_seq_elt(i, || e.encode(s));
+                s.emit_seq_elt(i, |s| e.encode(s));
                 i += 1;
             }
         }
@@ -569,11 +648,11 @@ impl<
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for @mut DList<T> {
-    fn decode(d: &D) -> @mut DList<T> {
+    fn decode(d: &mut D) -> @mut DList<T> {
         let list = DList();
-        do d.read_seq |len| {
+        do d.read_seq |d, len| {
             for uint::range(0, len) |i| {
-                list.push(d.read_seq_elt(i, || Decodable::decode(d)));
+                list.push(d.read_seq_elt(i, |d| Decodable::decode(d)));
             }
         }
         list
@@ -584,21 +663,21 @@ impl<
     S: Encoder,
     T: Encodable<S>
 > Encodable<S> for Deque<T> {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             for self.eachi |i, e| {
-                s.emit_seq_elt(i, || e.encode(s));
+                s.emit_seq_elt(i, |s| e.encode(s));
             }
         }
     }
 }
 
 impl<D:Decoder,T:Decodable<D>> Decodable<D> for Deque<T> {
-    fn decode(d: &D) -> Deque<T> {
+    fn decode(d: &mut D) -> Deque<T> {
         let mut deque = Deque::new();
-        do d.read_seq |len| {
+        do d.read_seq |d, len| {
             for uint::range(0, len) |i| {
-                deque.add_back(d.read_seq_elt(i, || Decodable::decode(d)));
+                deque.add_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
             }
         }
         deque
@@ -610,12 +689,12 @@ impl<
     K: Encodable<E> + Hash + IterBytes + Eq,
     V: Encodable<E>
 > Encodable<E> for HashMap<K, V> {
-    fn encode(&self, e: &E) {
-        do e.emit_map(self.len()) {
+    fn encode(&self, e: &mut E) {
+        do e.emit_map(self.len()) |e| {
             let mut i = 0;
             for self.each |key, val| {
-                e.emit_map_elt_key(i, || key.encode(e));
-                e.emit_map_elt_val(i, || val.encode(e));
+                e.emit_map_elt_key(i, |e| key.encode(e));
+                e.emit_map_elt_val(i, |e| val.encode(e));
                 i += 1;
             }
         }
@@ -627,12 +706,12 @@ impl<
     K: Decodable<D> + Hash + IterBytes + Eq,
     V: Decodable<D>
 > Decodable<D> for HashMap<K, V> {
-    fn decode(d: &D) -> HashMap<K, V> {
-        do d.read_map |len| {
+    fn decode(d: &mut D) -> HashMap<K, V> {
+        do d.read_map |d, len| {
             let mut map = HashMap::with_capacity(len);
             for uint::range(0, len) |i| {
-                let key = d.read_map_elt_key(i, || Decodable::decode(d));
-                let val = d.read_map_elt_val(i, || Decodable::decode(d));
+                let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
+                let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
                 map.insert(key, val);
             }
             map
@@ -644,11 +723,11 @@ impl<
     S: Encoder,
     T: Encodable<S> + Hash + IterBytes + Eq
 > Encodable<S> for HashSet<T> {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             let mut i = 0;
             for self.each |e| {
-                s.emit_seq_elt(i, || e.encode(s));
+                s.emit_seq_elt(i, |s| e.encode(s));
                 i += 1;
             }
         }
@@ -659,11 +738,11 @@ impl<
     D: Decoder,
     T: Decodable<D> + Hash + IterBytes + Eq
 > Decodable<D> for HashSet<T> {
-    fn decode(d: &D) -> HashSet<T> {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> HashSet<T> {
+        do d.read_seq |d, len| {
             let mut set = HashSet::with_capacity(len);
             for uint::range(0, len) |i| {
-                set.insert(d.read_seq_elt(i, || Decodable::decode(d)));
+                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
             }
             set
         }
@@ -674,12 +753,12 @@ impl<
     E: Encoder,
     V: Encodable<E>
 > Encodable<E> for TrieMap<V> {
-    fn encode(&self, e: &E) {
-        do e.emit_map(self.len()) {
+    fn encode(&self, e: &mut E) {
+        do e.emit_map(self.len()) |e| {
             let mut i = 0;
             for self.each |key, val| {
-                e.emit_map_elt_key(i, || key.encode(e));
-                e.emit_map_elt_val(i, || val.encode(e));
+                e.emit_map_elt_key(i, |e| key.encode(e));
+                e.emit_map_elt_val(i, |e| val.encode(e));
                 i += 1;
             }
         }
@@ -690,12 +769,12 @@ impl<
     D: Decoder,
     V: Decodable<D>
 > Decodable<D> for TrieMap<V> {
-    fn decode(d: &D) -> TrieMap<V> {
-        do d.read_map |len| {
+    fn decode(d: &mut D) -> TrieMap<V> {
+        do d.read_map |d, len| {
             let mut map = TrieMap::new();
             for uint::range(0, len) |i| {
-                let key = d.read_map_elt_key(i, || Decodable::decode(d));
-                let val = d.read_map_elt_val(i, || Decodable::decode(d));
+                let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
+                let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
                 map.insert(key, val);
             }
             map
@@ -704,11 +783,11 @@ impl<
 }
 
 impl<S: Encoder> Encodable<S> for TrieSet {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             let mut i = 0;
             for self.each |e| {
-                s.emit_seq_elt(i, || e.encode(s));
+                s.emit_seq_elt(i, |s| e.encode(s));
                 i += 1;
             }
         }
@@ -716,11 +795,11 @@ impl<S: Encoder> Encodable<S> for TrieSet {
 }
 
 impl<D: Decoder> Decodable<D> for TrieSet {
-    fn decode(d: &D) -> TrieSet {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> TrieSet {
+        do d.read_seq |d, len| {
             let mut set = TrieSet::new();
             for uint::range(0, len) |i| {
-                set.insert(d.read_seq_elt(i, || Decodable::decode(d)));
+                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
             }
             set
         }
@@ -732,12 +811,12 @@ impl<
     K: Encodable<E> + Eq + TotalOrd,
     V: Encodable<E> + Eq
 > Encodable<E> for TreeMap<K, V> {
-    fn encode(&self, e: &E) {
-        do e.emit_map(self.len()) {
+    fn encode(&self, e: &mut E) {
+        do e.emit_map(self.len()) |e| {
             let mut i = 0;
             for self.each |key, val| {
-                e.emit_map_elt_key(i, || key.encode(e));
-                e.emit_map_elt_val(i, || val.encode(e));
+                e.emit_map_elt_key(i, |e| key.encode(e));
+                e.emit_map_elt_val(i, |e| val.encode(e));
                 i += 1;
             }
         }
@@ -749,12 +828,12 @@ impl<
     K: Decodable<D> + Eq + TotalOrd,
     V: Decodable<D> + Eq
 > Decodable<D> for TreeMap<K, V> {
-    fn decode(d: &D) -> TreeMap<K, V> {
-        do d.read_map |len| {
+    fn decode(d: &mut D) -> TreeMap<K, V> {
+        do d.read_map |d, len| {
             let mut map = TreeMap::new();
             for uint::range(0, len) |i| {
-                let key = d.read_map_elt_key(i, || Decodable::decode(d));
-                let val = d.read_map_elt_val(i, || Decodable::decode(d));
+                let key = d.read_map_elt_key(i, |d| Decodable::decode(d));
+                let val = d.read_map_elt_val(i, |d| Decodable::decode(d));
                 map.insert(key, val);
             }
             map
@@ -766,11 +845,11 @@ impl<
     S: Encoder,
     T: Encodable<S> + Eq + TotalOrd
 > Encodable<S> for TreeSet<T> {
-    fn encode(&self, s: &S) {
-        do s.emit_seq(self.len()) {
+    fn encode(&self, s: &mut S) {
+        do s.emit_seq(self.len()) |s| {
             let mut i = 0;
             for self.each |e| {
-                s.emit_seq_elt(i, || e.encode(s));
+                s.emit_seq_elt(i, |s| e.encode(s));
                 i += 1;
             }
         }
@@ -781,11 +860,11 @@ impl<
     D: Decoder,
     T: Decodable<D> + Eq + TotalOrd
 > Decodable<D> for TreeSet<T> {
-    fn decode(d: &D) -> TreeSet<T> {
-        do d.read_seq |len| {
+    fn decode(d: &mut D) -> TreeSet<T> {
+        do d.read_seq |d, len| {
             let mut set = TreeSet::new();
             for uint::range(0, len) |i| {
-                set.insert(d.read_seq_elt(i, || Decodable::decode(d)));
+                set.insert(d.read_seq_elt(i, |d| Decodable::decode(d)));
             }
             set
         }
@@ -798,15 +877,15 @@ impl<
 // In some cases, these should eventually be coded as traits.
 
 pub trait EncoderHelpers {
-    fn emit_from_vec<T>(&self, v: &[T], f: &fn(v: &T));
+    fn emit_from_vec<T>(&mut self, v: &[T], f: &fn(&mut Self, v: &T));
 }
 
 impl<S:Encoder> EncoderHelpers for S {
-    fn emit_from_vec<T>(&self, v: &[T], f: &fn(v: &T)) {
-        do self.emit_seq(v.len()) {
+    fn emit_from_vec<T>(&mut self, v: &[T], f: &fn(&mut S, &T)) {
+        do self.emit_seq(v.len()) |this| {
             for v.eachi |i, e| {
-                do self.emit_seq_elt(i) {
-                    f(e)
+                do this.emit_seq_elt(i) |this| {
+                    f(this, e)
                 }
             }
         }
@@ -814,14 +893,14 @@ impl<S:Encoder> EncoderHelpers for S {
 }
 
 pub trait DecoderHelpers {
-    fn read_to_vec<T>(&self, f: &fn() -> T) -> ~[T];
+    fn read_to_vec<T>(&mut self, f: &fn(&mut Self) -> T) -> ~[T];
 }
 
 impl<D:Decoder> DecoderHelpers for D {
-    fn read_to_vec<T>(&self, f: &fn() -> T) -> ~[T] {
-        do self.read_seq |len| {
+    fn read_to_vec<T>(&mut self, f: &fn(&mut D) -> T) -> ~[T] {
+        do self.read_seq |this, len| {
             do vec::from_fn(len) |i| {
-                self.read_seq_elt(i, || f())
+                this.read_seq_elt(i, |this| f(this))
             }
         }
     }
diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs
index 7371250b38a..a8e0f7d062a 100644
--- a/src/libstd/sha1.rs
+++ b/src/libstd/sha1.rs
@@ -412,11 +412,3 @@ mod tests {
         }
     }
 }
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs
index 119b47c904e..a18e2f47a77 100644
--- a/src/libstd/sort.rs
+++ b/src/libstd/sort.rs
@@ -1236,11 +1236,3 @@ mod big_tests {
         }
     }
 }
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/std.rc b/src/libstd/std.rc
index 9d1ddb8ec54..a326af804bd 100644
--- a/src/libstd/std.rc
+++ b/src/libstd/std.rc
@@ -124,11 +124,3 @@ pub mod std {
     pub use serialize;
     pub use test;
 }
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/task_pool.rs b/src/libstd/task_pool.rs
index 82053602755..661247df1c1 100644
--- a/src/libstd/task_pool.rs
+++ b/src/libstd/task_pool.rs
@@ -100,4 +100,3 @@ fn test_task_pool() {
         pool.execute(|i| io::println(fmt!("Hello from thread %u!", *i)));
     }
 }
-
diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs
index eec91b68454..10645e947e2 100644
--- a/src/libstd/tempfile.rs
+++ b/src/libstd/tempfile.rs
@@ -27,6 +27,7 @@ pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
 mod tests {
     use tempfile::mkdtemp;
     use tempfile;
+    use core::os;
 
     #[test]
     fn test_mkdtemp() {
@@ -42,13 +43,18 @@ mod tests {
         use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
         use core::os;
 
-        let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel");
-        os::change_dir(&root);
-        let path = Path("frob");
-        assert!(os::mkdir_recursive(&path,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
-        assert!(os::path_is_dir(&path));
-        assert!(os::mkdir_recursive(&path,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
-        assert!(os::path_is_dir(&path));
+        let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel").
+            expect("recursive_mkdir_rel");
+        assert!(do os::change_dir_locked(&root) {
+            let path = Path("frob");
+            debug!("recursive_mkdir_rel: Making: %s in cwd %s [%?]", path.to_str(),
+                   os::getcwd().to_str(),
+                   os::path_exists(&path));
+            assert!(os::mkdir_recursive(&path,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+            assert!(os::path_is_dir(&path));
+            assert!(os::mkdir_recursive(&path,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+            assert!(os::path_is_dir(&path));
+        });
     }
 
     #[test]
@@ -67,18 +73,44 @@ mod tests {
         use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
         use core::os;
 
-        let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel_2");
-        os::change_dir(&root);
-        let path = Path("./frob/baz");
-        debug!("...Making: %s in cwd %s", path.to_str(), os::getcwd().to_str());
-        assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
-        assert!(os::path_is_dir(&path));
-        assert!(os::path_is_dir(&path.pop()));
-        let path2 = Path("quux/blat");
-        debug!("Making: %s in cwd %s", path2.to_str(), os::getcwd().to_str());
-        assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
-        assert!(os::path_is_dir(&path2));
-        assert!(os::path_is_dir(&path2.pop()));
+        let root = mkdtemp(&os::tmpdir(), "recursive_mkdir_rel_2").
+            expect("recursive_mkdir_rel_2");
+        assert!(do os::change_dir_locked(&root) {
+            let path = Path("./frob/baz");
+            debug!("recursive_mkdir_rel_2: Making: %s in cwd %s [%?]", path.to_str(),
+                   os::getcwd().to_str(), os::path_exists(&path));
+            assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+                assert!(os::path_is_dir(&path));
+            assert!(os::path_is_dir(&path.pop()));
+            let path2 = Path("quux/blat");
+            debug!("recursive_mkdir_rel_2: Making: %s in cwd %s", path2.to_str(),
+                   os::getcwd().to_str());
+            assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+                assert!(os::path_is_dir(&path2));
+            assert!(os::path_is_dir(&path2.pop()));
+        });
     }
 
-}
\ No newline at end of file
+    // Ideally this would be in core, but needs mkdtemp
+    #[test]
+    pub fn test_rmdir_recursive_ok() {
+        use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
+        use core::os;
+
+        let rwx = (S_IRUSR | S_IWUSR | S_IXUSR) as i32;
+
+        let tmpdir = mkdtemp(&os::tmpdir(), "test").expect("test_rmdir_recursive_ok: \
+                                            couldn't create temp dir");
+        let root = tmpdir.push("foo");
+
+        debug!("making %s", root.to_str());
+        assert!(os::make_dir(&root, rwx));
+        assert!(os::make_dir(&root.push("foo"), rwx));
+        assert!(os::make_dir(&root.push("foo").push("bar"), rwx));
+        assert!(os::make_dir(&root.push("foo").push("bar").push("blat"), rwx));
+        assert!(os::remove_dir_recursive(&root));
+        assert!(!os::path_exists(&root));
+        assert!(!os::path_exists(&root.push("bar")));
+        assert!(!os::path_exists(&root.push("bar").push("blat")));
+    }
+}
diff --git a/src/libstd/term.rs b/src/libstd/term.rs
index 022f1f8564e..a79b9f4c849 100644
--- a/src/libstd/term.rs
+++ b/src/libstd/term.rs
@@ -76,10 +76,3 @@ pub fn fg(writer: @io::Writer, color: u8) {
 pub fn bg(writer: @io::Writer, color: u8) {
     return set_color(writer, '4' as u8, color);
 }
-
-// Local Variables:
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/test.rs b/src/libstd/test.rs
index 278a326d1de..65fb0c7426a 100644
--- a/src/libstd/test.rs
+++ b/src/libstd/test.rs
@@ -960,12 +960,3 @@ mod tests {
         }
     }
 }
-
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs
index c01d1f5a2d7..e681382ffc8 100644
--- a/src/libstd/workcache.rs
+++ b/src/libstd/workcache.rs
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#[allow(deprecated_mode)];
-
 use json;
 use sha1;
 use serialize::{Encoder, Encodable, Decoder, Decodable};
@@ -141,7 +139,7 @@ impl WorkMap {
 }
 
 impl<S:Encoder> Encodable<S> for WorkMap {
-    fn encode(&self, s: &S) {
+    fn encode(&self, s: &mut S) {
         let mut d = ~[];
         for self.each |k, v| {
             d.push((copy *k, copy *v))
@@ -152,7 +150,7 @@ impl<S:Encoder> Encodable<S> for WorkMap {
 }
 
 impl<D:Decoder> Decodable<D> for WorkMap {
-    fn decode(d: &D) -> WorkMap {
+    fn decode(d: &mut D) -> WorkMap {
         let v : ~[(WorkKey,~str)] = Decodable::decode(d);
         let mut w = WorkMap::new();
         for v.each |&(k, v)| {
@@ -171,8 +169,8 @@ struct Database {
 pub impl Database {
     fn prepare(&mut self,
                fn_name: &str,
-               declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)>
-    {
+               declared_inputs: &WorkMap)
+               -> Option<(WorkMap, WorkMap, ~str)> {
         let k = json_encode(&(fn_name, declared_inputs));
         match self.db_cache.find(&k) {
             None => None,
@@ -231,7 +229,8 @@ struct Work<T> {
 
 fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
     do io::with_str_writer |wr| {
-        t.encode(&json::Encoder(wr));
+        let mut encoder = json::Encoder(wr);
+        t.encode(&mut encoder);
     }
 }
 
@@ -239,7 +238,8 @@ fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
 fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
     do io::with_str_reader(s) |rdr| {
         let j = result::unwrap(json::from_reader(rdr));
-        Decodable::decode(&json::Decoder(j))
+        let mut decoder = json::Decoder(j);
+        Decodable::decode(&mut decoder)
     }
 }