about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-02-13 15:09:07 -0800
committerbors <bors@rust-lang.org>2013-02-13 15:09:07 -0800
commitd5bf3b85d1078f3a2dd4cb9f009af018c2b4c062 (patch)
tree7b1b8b8dc6121350b854cd3496fed65100683313 /src/libstd
parent5e6d7871c656145a5530b653882a3ce26f40c163 (diff)
parente6c82c0375e042e062079c056e5e3ac31eb86005 (diff)
downloadrust-d5bf3b85d1078f3a2dd4cb9f009af018c2b4c062.tar.gz
rust-d5bf3b85d1078f3a2dd4cb9f009af018c2b4c062.zip
auto merge of #4908 : bstrie/rust/rimov3, r=pcwalton
This patch finishes removing inner vector mutability from the vast majority of the compiler. Exceptions:

* core::dvec: ideally this entire type will be able to be replaced by `~[]`, but Niko asked me to hold off on removing Dvecs until he makes some fixes to borrowed pointers. 
* liveness: liveness.rs is an impenetrable neutron star of deprecated semantics.
* compile-fail: I'm not sure if a lot of these tests are testing inner mutability or mutability in general. I figure that RIMOVing this folder should wait until this syntax is removed from the parser.

I also took this chance to remove many of the inner-mutability-related functions from core::vec, or as many uses of those functions as possible where still necessary. consume_mut and append_mut have been axed. cast_to_mut and cast_from_mut are still needed in a few places.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/getopts.rs4
-rw-r--r--src/libstd/md4.rs2
-rw-r--r--src/libstd/rope.rs6
-rw-r--r--src/libstd/sha1.rs68
-rw-r--r--src/libstd/sort.rs4
-rw-r--r--src/libstd/workcache.rs4
6 files changed, 44 insertions, 44 deletions
diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs
index a778649f6f4..e3f8ef1b2b5 100644
--- a/src/libstd/getopts.rs
+++ b/src/libstd/getopts.rs
@@ -224,7 +224,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
     unsafe {
         let n_opts = opts.len();
         fn f(_x: uint) -> ~[Optval] { return ~[]; }
-        let vals = vec::cast_to_mut(vec::from_fn(n_opts, f));
+        let mut vals = vec::from_fn(n_opts, f);
         let mut free: ~[~str] = ~[];
         let l = args.len();
         let mut i = 0;
@@ -339,7 +339,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
             i += 1;
         }
         return Ok(Matches {opts: vec::from_slice(opts),
-                   vals: vec::cast_from_mut(move vals),
+                   vals: move vals,
                    free: free});
     }
 }
diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs
index 1d831af0e29..6fe82d554de 100644
--- a/src/libstd/md4.rs
+++ b/src/libstd/md4.rs
@@ -52,7 +52,7 @@ pub pure fn md4(msg: &[u8]) -> Quad {
 
     let mut i = 0u;
     let e = vec::len(msg);
-    let x = vec::cast_to_mut(vec::from_elem(16u, 0u32));
+    let mut x = vec::from_elem(16u, 0u32);
     while i < e {
         let aa = a, bb = b, cc = c, dd = d;
 
diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs
index f8aef2c5f1e..dbfa771e0a2 100644
--- a/src/libstd/rope.rs
+++ b/src/libstd/rope.rs
@@ -174,7 +174,7 @@ pub fn concat(v: ~[Rope]) -> Rope {
     //Copy `v` into a mut vector
     let mut len = vec::len(v);
     if len == 0u { return node::Empty; }
-    let ropes = vec::cast_to_mut(vec::from_elem(len, v[0]));
+    let mut ropes = vec::from_elem(len, v[0]);
     for uint::range(1u, len) |i| {
        ropes[i] = v[i];
     }
@@ -719,7 +719,7 @@ pub mod node {
             //Firstly, split `str` in slices of hint_max_leaf_char_len
             let mut leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
             //Number of leaves
-            let nodes  = vec::cast_to_mut(vec::from_elem(leaves, candidate));
+            let mut nodes  = vec::from_elem(leaves, candidate);
 
             let mut i = 0u;
             let mut offset = byte_start;
@@ -832,7 +832,7 @@ pub mod node {
 
     pub fn serialize_node(node: @Node) -> ~str {
         unsafe {
-            let mut buf = vec::cast_to_mut(vec::from_elem(byte_len(node), 0));
+            let mut buf = vec::from_elem(byte_len(node), 0);
             let mut offset = 0u;//Current position in the buffer
             let it = leaf_iterator::start(node);
             loop {
diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs
index 6209170ac3d..788d1d1012d 100644
--- a/src/libstd/sha1.rs
+++ b/src/libstd/sha1.rs
@@ -35,21 +35,21 @@ use core::vec;
 /// The SHA-1 interface
 trait Sha1 {
     /// Provide message input as bytes
-    fn input(&[const u8]);
+    fn input(&mut self, &[const u8]);
     /// Provide message input as string
-    fn input_str(&str);
+    fn input_str(&mut self, &str);
     /**
      * Read the digest as a vector of 20 bytes. After calling this no further
      * input may be provided until reset is called.
      */
-    fn result() -> ~[u8];
+    fn result(&mut self) -> ~[u8];
     /**
      * Read the digest as a hex string. After calling this no further
      * input may be provided until reset is called.
      */
-    fn result_str() -> ~str;
+    fn result_str(&mut self) -> ~str;
     /// Reset the SHA-1 state for reuse
-    fn reset();
+    fn reset(&mut self);
 }
 
 // Some unexported constants
@@ -65,15 +65,15 @@ const k3: u32 = 0xCA62C1D6u32;
 /// Construct a `sha` object
 pub fn sha1() -> Sha1 {
     struct Sha1State
-        {h: ~[mut u32],
-         mut len_low: u32,
-         mut len_high: u32,
-         msg_block: ~[mut u8],
-         mut msg_block_idx: uint,
-         mut computed: bool,
-         work_buf: @~[mut u32]};
+        { h: ~[u32],
+          len_low: u32,
+          len_high: u32,
+          msg_block: ~[u8],
+          msg_block_idx: uint,
+          computed: bool,
+          work_buf: @mut ~[u32]};
 
-    fn add_input(st: &Sha1State, msg: &[const u8]) {
+    fn add_input(st: &mut Sha1State, msg: &[const u8]) {
         assert (!st.computed);
         for vec::each_const(msg) |element| {
             st.msg_block[st.msg_block_idx] = *element;
@@ -89,11 +89,11 @@ pub fn sha1() -> Sha1 {
             if st.msg_block_idx == msg_block_len { process_msg_block(st); }
         }
     }
-    fn process_msg_block(st: &Sha1State) {
+    fn process_msg_block(st: &mut Sha1State) {
         assert (vec::len(st.h) == digest_buf_len);
         assert (vec::len(*st.work_buf) == work_buf_len);
         let mut t: int; // Loop counter
-        let w = st.work_buf;
+        let mut w = st.work_buf;
 
         // Initialize the first 16 words of the vector w
         t = 0;
@@ -168,7 +168,7 @@ pub fn sha1() -> Sha1 {
     fn circular_shift(bits: u32, word: u32) -> u32 {
         return word << bits | word >> 32u32 - bits;
     }
-    fn mk_result(st: &Sha1State) -> ~[u8] {
+    fn mk_result(st: &mut Sha1State) -> ~[u8] {
         if !(*st).computed { pad_msg(st); (*st).computed = true; }
         let mut rs: ~[u8] = ~[];
         for vec::each_mut((*st).h) |ptr_hpart| {
@@ -191,7 +191,7 @@ pub fn sha1() -> Sha1 {
      * call process_msg_block() appropriately.  When it returns, it
      * can be assumed that the message digest has been computed.
      */
-    fn pad_msg(st: &Sha1State) {
+    fn pad_msg(st: &mut Sha1State) {
         assert (vec::len((*st).msg_block) == msg_block_len);
 
         /*
@@ -229,7 +229,7 @@ pub fn sha1() -> Sha1 {
     }
 
     impl Sha1State: Sha1 {
-        fn reset() {
+        fn reset(&mut self) {
             assert (vec::len(self.h) == digest_buf_len);
             self.len_low = 0u32;
             self.len_high = 0u32;
@@ -241,14 +241,14 @@ pub fn sha1() -> Sha1 {
             self.h[4] = 0xC3D2E1F0u32;
             self.computed = false;
         }
-        fn input(msg: &[const u8]) { add_input(&self, msg); }
-        fn input_str(msg: &str) {
+        fn input(&mut self, msg: &[const u8]) { add_input(self, msg); }
+        fn input_str(&mut self, msg: &str) {
             let bs = str::to_bytes(msg);
-            add_input(&self, bs);
+            add_input(self, bs);
         }
-        fn result() -> ~[u8] { return mk_result(&self); }
-        fn result_str() -> ~str {
-            let rr = mk_result(&self);
+        fn result(&mut self) -> ~[u8] { return mk_result(self); }
+        fn result_str(&mut self) -> ~str {
+            let rr = mk_result(self);
             let mut s = ~"";
             for vec::each(rr) |b| {
                 s += uint::to_str_radix(*b as uint, 16u);
@@ -256,16 +256,16 @@ pub fn sha1() -> Sha1 {
             return s;
         }
     }
-    let st = Sha1State {
-        h: vec::cast_to_mut(vec::from_elem(digest_buf_len, 0u32)),
-        mut len_low: 0u32,
-        mut len_high: 0u32,
-        msg_block: vec::cast_to_mut(vec::from_elem(msg_block_len, 0u8)),
-        mut msg_block_idx: 0u,
-        mut computed: false,
-        work_buf: @vec::cast_to_mut(vec::from_elem(work_buf_len, 0u32))
+    let mut st = Sha1State {
+         h: vec::from_elem(digest_buf_len, 0u32),
+         len_low: 0u32,
+         len_high: 0u32,
+         msg_block: vec::from_elem(msg_block_len, 0u8),
+         msg_block_idx: 0u,
+         computed: false,
+         work_buf: @mut vec::from_elem(work_buf_len, 0u32)
     };
-    let sh = (move st) as Sha1;
+    let mut sh = (move st) as Sha1;
     sh.reset();
     return sh;
 }
@@ -368,7 +368,7 @@ mod tests {
             }
             // Test that it works when accepting the message all at once
 
-            let sh = sha1::sha1();
+            let mut sh = sha1::sha1();
             for vec::each(tests) |t| {
                 sh.input_str(t.input);
                 let out = sh.result();
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs
index 680a2b99c4a..9c7d31e15f3 100644
--- a/src/libstd/sort.rs
+++ b/src/libstd/sort.rs
@@ -455,7 +455,7 @@ impl<T: Copy Ord> MergeState<T> {
                 base2: uint, len2: uint) {
         assert len1 != 0 && len2 != 0 && base1+len1 == base2;
 
-        let tmp = vec::cast_to_mut(vec::slice(array, base1, base1+len1));
+        let mut tmp = vec::slice(array, base1, base1+len1);
 
         let mut c1 = 0;
         let mut c2 = base2;
@@ -558,7 +558,7 @@ impl<T: Copy Ord> MergeState<T> {
                 base2: uint, len2: uint) {
         assert len1 != 1 && len2 != 0 && base1 + len1 == base2;
 
-        let tmp = vec::cast_to_mut(vec::slice(array, base2, base2+len2));
+        let mut tmp = vec::slice(array, base2, base2+len2);
 
         let mut c1 = base1 + len1 - 1;
         let mut c2 = len2 - 1;
diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs
index 593d26d0124..69116ace9e8 100644
--- a/src/libstd/workcache.rs
+++ b/src/libstd/workcache.rs
@@ -242,13 +242,13 @@ fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
 }
 
 fn digest<T:Encodable<json::Encoder>>(t: &T) -> ~str {
-    let sha = sha1::sha1();
+    let mut sha = sha1::sha1();
     sha.input_str(json_encode(t));
     sha.result_str()
 }
 
 fn digest_file(path: &Path) -> ~str {
-    let sha = sha1::sha1();
+    let mut sha = sha1::sha1();
     let s = io::read_whole_file_str(path);
     sha.input_str(*s.get_ref());
     sha.result_str()