about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-06-04 21:43:41 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-06-04 21:45:42 -0700
commit8114d0e9505b44856b822dd587293fd7895320e4 (patch)
tree1e738ee1a533e43733225d9a66b065fb550b6dc7 /src/libstd
parent16086ecff7edda82b114a72948762d59095f6fb4 (diff)
downloadrust-8114d0e9505b44856b822dd587293fd7895320e4.tar.gz
rust-8114d0e9505b44856b822dd587293fd7895320e4.zip
librustc: Disallow multiple patterns from appearing in a "let" declaration.
You can still initialize multiple variables at once with "let (x, y) = (1, 2)".
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io.rs8
-rw-r--r--src/libstd/managed.rs4
-rw-r--r--src/libstd/num/int_macros.rs2
-rw-r--r--src/libstd/num/uint_macros.rs2
-rw-r--r--src/libstd/rand.rs19
-rw-r--r--src/libstd/rand/distributions.rs2
-rw-r--r--src/libstd/rt/io/extensions.rs4
-rw-r--r--src/libstd/rt/uv/mod.rs2
-rw-r--r--src/libstd/str.rs27
-rw-r--r--src/libstd/to_str.rs30
-rw-r--r--src/libstd/tuple.rs2
-rw-r--r--src/libstd/vec.rs6
12 files changed, 57 insertions, 51 deletions
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index 8fe592db403..e3977ca0067 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -771,7 +771,7 @@ impl<T:Reader> ReaderUtil for T {
     fn read_le_uint_n(&self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut val = 0u64, pos = 0, i = nbytes;
+        let mut (val, pos, i) = (0u64, 0, nbytes);
         while i > 0 {
             val += (self.read_u8() as u64) << pos;
             pos += 8;
@@ -787,7 +787,7 @@ impl<T:Reader> ReaderUtil for T {
     fn read_be_uint_n(&self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut val = 0u64, i = nbytes;
+        let mut (val, i) = (0u64, nbytes);
         while i > 0 {
             i -= 1;
             val += (self.read_u8() as u64) << i * 8;
@@ -1304,7 +1304,9 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
               (n >> 56) as u8]),
       _ => {
 
-        let mut bytes: ~[u8] = ~[], i = size, n = n;
+        let mut bytes: ~[u8] = ~[];
+        let mut i = size;
+        let mut n = n;
         while i > 0u {
             bytes.push((n & 255_u64) as u8);
             n >>= 8_u64;
diff --git a/src/libstd/managed.rs b/src/libstd/managed.rs
index fb6ac7603ca..7d0defea05a 100644
--- a/src/libstd/managed.rs
+++ b/src/libstd/managed.rs
@@ -40,14 +40,14 @@ pub mod raw {
 /// Determine if two shared boxes point to the same object
 #[inline(always)]
 pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
-    let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
+    let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
     a_ptr == b_ptr
 }
 
 /// Determine if two mutable shared boxes point to the same object
 #[inline(always)]
 pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
-    let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
+    let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
     a_ptr == b_ptr
 }
 
diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs
index 023f44c433c..3583e2f366f 100644
--- a/src/libstd/num/int_macros.rs
+++ b/src/libstd/num/int_macros.rs
@@ -400,7 +400,7 @@ impl Integer for $T {
     #[inline(always)]
     fn gcd(&self, other: &$T) -> $T {
         // Use Euclid's algorithm
-        let mut m = *self, n = *other;
+        let mut (m, n) = (*self, *other);
         while m != 0 {
             let temp = m;
             m = n % temp;
diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs
index bdb74f7e191..a7aebf1f176 100644
--- a/src/libstd/num/uint_macros.rs
+++ b/src/libstd/num/uint_macros.rs
@@ -237,7 +237,7 @@ impl Integer for $T {
     #[inline(always)]
     fn gcd(&self, other: &$T) -> $T {
         // Use Euclid's algorithm
-        let mut m = *self, n = *other;
+        let mut (m, n) = (*self, *other);
         while m != 0 {
             let temp = m;
             m = n % temp;
diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs
index 40d1744f0fb..a6c1dca4342 100644
--- a/src/libstd/rand.rs
+++ b/src/libstd/rand.rs
@@ -658,13 +658,14 @@ impl IsaacRng {
     /// of `rsl` as a seed, otherwise construct one algorithmically (not
     /// randomly).
     fn init(&mut self, use_rsl: bool) {
-        macro_rules! init_mut_many (
-            ($( $var:ident ),* = $val:expr ) => {
-                let mut $( $var = $val ),*;
-            }
-        );
-        init_mut_many!(a, b, c, d, e, f, g, h = 0x9e3779b9);
-
+        let mut a = 0x9e3779b9;
+        let mut b = a;
+        let mut c = a;
+        let mut d = a;
+        let mut e = a;
+        let mut f = a;
+        let mut g = a;
+        let mut h = a;
 
         macro_rules! mix(
             () => {{
@@ -718,9 +719,9 @@ impl IsaacRng {
     fn isaac(&mut self) {
         self.c += 1;
         // abbreviations
-        let mut a = self.a, b = self.b + self.c;
+        let mut (a, b) = (self.a, self.b + self.c);
 
-        static midpoint: uint =  RAND_SIZE as uint / 2;
+        static midpoint: uint = RAND_SIZE as uint / 2;
 
         macro_rules! ind (($x:expr) => {
             self.mem[($x >> 2) & (RAND_SIZE - 1)]
diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs
index cf2733976c4..f08d967cbe0 100644
--- a/src/libstd/rand/distributions.rs
+++ b/src/libstd/rand/distributions.rs
@@ -89,7 +89,7 @@ impl Rand for StandardNormal {
             // do-while, so the condition should be true on the first
             // run, they get overwritten anyway (0 < 1, so these are
             // good).
-            let mut x = 1.0, y = 0.0;
+            let mut (x, y) = (1.0, 0.0);
 
             // XXX infinities?
             while -2.0*y < x * x {
diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs
index 7d6d89ce997..727ab13a4f6 100644
--- a/src/libstd/rt/io/extensions.rs
+++ b/src/libstd/rt/io/extensions.rs
@@ -342,7 +342,7 @@ impl<T: Reader> ReaderByteConversions for T {
     fn read_le_uint_n(&mut self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut val = 0u64, pos = 0, i = nbytes;
+        let mut (val, pos, i) = (0u64, 0, nbytes);
         while i > 0 {
             val += (self.read_u8() as u64) << pos;
             pos += 8;
@@ -358,7 +358,7 @@ impl<T: Reader> ReaderByteConversions for T {
     fn read_be_uint_n(&mut self, nbytes: uint) -> u64 {
         assert!(nbytes > 0 && nbytes <= 8);
 
-        let mut val = 0u64, i = nbytes;
+        let mut (val, i) = (0u64, nbytes);
         while i > 0 {
             i -= 1;
             val += (self.read_u8() as u64) << i * 8;
diff --git a/src/libstd/rt/uv/mod.rs b/src/libstd/rt/uv/mod.rs
index 84d1e65454f..10c8b84bc51 100644
--- a/src/libstd/rt/uv/mod.rs
+++ b/src/libstd/rt/uv/mod.rs
@@ -242,7 +242,7 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
     // XXX: Could go in str::raw
     unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
         let s = s as *u8;
-        let mut curr = s, len = 0u;
+        let mut (curr, len) = (s, 0u);
         while *curr != 0u8 {
             len += 1u;
             curr = ptr::offset(s, len);
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index b7de9e20559..da9ee21583d 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -661,9 +661,9 @@ fn each_split_char_inner<'a>(s: &'a str,
                              allow_trailing_empty: bool,
                              it: &fn(&'a str) -> bool) -> bool {
     if sep < 128u as char {
-        let b = sep as u8, l = len(s);
+        let (b, l) = (sep as u8, len(s));
         let mut done = 0u;
-        let mut i = 0u, start = 0u;
+        let mut (i, start) = (0u, 0u);
         while i < l && done < count {
             if s[i] == b {
                 if allow_empty || start < i {
@@ -725,7 +725,7 @@ fn each_split_inner<'a>(s: &'a str,
                         allow_trailing_empty: bool,
                         it: &fn(&'a str) -> bool) -> bool {
     let l = len(s);
-    let mut i = 0u, start = 0u, done = 0u;
+    let mut (i, start, done) = (0u, 0u, 0u);
     while i < l && done < count {
         let CharRange {ch, next} = char_range_at(s, i);
         if sepfn(ch) {
@@ -748,9 +748,9 @@ fn each_split_inner<'a>(s: &'a str,
 // See Issue #1932 for why this is a naive search
 fn iter_matches<'a,'b>(s: &'a str, sep: &'b str,
                        f: &fn(uint, uint) -> bool) -> bool {
-    let sep_len = len(sep), l = len(s);
+    let (sep_len, l) = (len(sep), len(s));
     assert!(sep_len > 0u);
-    let mut i = 0u, match_start = 0u, match_i = 0u;
+    let mut (i, match_start, match_i) = (0u, 0u, 0u);
 
     while i < l {
         if s[i] == sep[match_i] {
@@ -977,7 +977,7 @@ pub fn each_split_within<'a>(ss: &'a str,
  * The original string with all occurances of `from` replaced with `to`
  */
 pub fn replace(s: &str, from: &str, to: &str) -> ~str {
-    let mut result = ~"", first = true;
+    let mut (result, first) = (~"", true);
     for iter_between_matches(s, from) |start, end| {
         if first {
             first = false;
@@ -1761,7 +1761,7 @@ pub fn contains_char(haystack: &str, needle: char) -> bool {
  * * needle - The string to look for
  */
 pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
-    let haystack_len = len(haystack), needle_len = len(needle);
+    let (haystack_len, needle_len) = (len(haystack), len(needle));
     if needle_len == 0u { true }
     else if needle_len > haystack_len { false }
     else { match_at(haystack, needle, 0u) }
@@ -1776,7 +1776,7 @@ pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
  * * needle - The string to look for
  */
 pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
-    let haystack_len = len(haystack), needle_len = len(needle);
+    let (haystack_len, needle_len) = (len(haystack), len(needle));
     if needle_len == 0u { true }
     else if needle_len > haystack_len { false }
     else { match_at(haystack, needle, haystack_len - needle_len) }
@@ -1951,7 +1951,7 @@ pub fn with_capacity(capacity: uint) -> ~str {
 pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
     assert!(is_char_boundary(s, start));
     assert!(is_char_boundary(s, end));
-    let mut i = start, len = 0u;
+    let mut (i, len) = (start, 0u);
     while i < end {
         let next = char_range_at(s, i).next;
         len += 1u;
@@ -1964,7 +1964,7 @@ pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
 /// starting from `start`.
 pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
     assert!(is_char_boundary(s, start));
-    let mut end = start, cnt = n;
+    let mut (end, cnt) = (start, n);
     let l = len(s);
     while cnt > 0u {
         assert!(end < l);
@@ -2300,7 +2300,10 @@ pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
 pub fn subslice_offset(outer: &str, inner: &str) -> uint {
     do as_buf(outer) |a, a_len| {
         do as_buf(inner) |b, b_len| {
-            let a_start: uint, a_end: uint, b_start: uint, b_end: uint;
+            let a_start: uint;
+            let a_end: uint;
+            let b_start: uint;
+            let b_end: uint;
             unsafe {
                 a_start = cast::transmute(a); a_end = a_len + cast::transmute(a);
                 b_start = cast::transmute(b); b_end = b_len + cast::transmute(b);
@@ -2404,7 +2407,7 @@ pub mod raw {
 
     /// Create a Rust string from a null-terminated *u8 buffer
     pub unsafe fn from_buf(buf: *u8) -> ~str {
-        let mut curr = buf, i = 0u;
+        let mut (curr, i) = (buf, 0u);
         while *curr != 0u8 {
             i += 1u;
             curr = ptr::offset(buf, i);
diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs
index fecfdbf3b11..3cc64147964 100644
--- a/src/libstd/to_str.rs
+++ b/src/libstd/to_str.rs
@@ -53,7 +53,7 @@ impl<A:ToStr> ToStr for (A,) {
 impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
     #[inline(always)]
     fn to_str(&self) -> ~str {
-        let mut acc = ~"{", first = true;
+        let mut (acc, first) = (~"{", true);
         for self.each |key, value| {
             if first {
                 first = false;
@@ -73,18 +73,18 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
 impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
     #[inline(always)]
     fn to_str(&self) -> ~str {
-    let mut acc = ~"{", first = true;
-    for self.each |element| {
-        if first {
-            first = false;
-        }
-        else {
-            acc.push_str(", ");
+        let mut (acc, first) = (~"{", true);
+        for self.each |element| {
+            if first {
+                first = false;
+            }
+            else {
+                acc.push_str(", ");
+            }
+            acc.push_str(element.to_str());
         }
-        acc.push_str(element.to_str());
-    }
-    acc.push_char('}');
-    acc
+        acc.push_char('}');
+        acc
     }
 }
 
@@ -121,7 +121,7 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
 impl<'self,A:ToStr> ToStr for &'self [A] {
     #[inline(always)]
     fn to_str(&self) -> ~str {
-        let mut acc = ~"[", first = true;
+        let mut (acc, first) = (~"[", true);
         for self.each |elt| {
             if first {
                 first = false;
@@ -139,7 +139,7 @@ impl<'self,A:ToStr> ToStr for &'self [A] {
 impl<A:ToStr> ToStr for ~[A] {
     #[inline(always)]
     fn to_str(&self) -> ~str {
-        let mut acc = ~"[", first = true;
+        let mut (acc, first) = (~"[", true);
         for self.each |elt| {
             if first {
                 first = false;
@@ -157,7 +157,7 @@ impl<A:ToStr> ToStr for ~[A] {
 impl<A:ToStr> ToStr for @[A] {
     #[inline(always)]
     fn to_str(&self) -> ~str {
-        let mut acc = ~"[", first = true;
+        let mut (acc, first) = (~"[", true);
         for self.each |elt| {
             if first {
                 first = false;
diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs
index da2c52014e8..589c18de0ab 100644
--- a/src/libstd/tuple.rs
+++ b/src/libstd/tuple.rs
@@ -412,7 +412,7 @@ mod tests {
 
     #[test]
     fn test_tuple_cmp() {
-        let small = (1u, 2u, 3u), big = (3u, 2u, 1u);
+        let (small, big) = ((1u, 2u, 3u), (3u, 2u, 1u));
 
         // Eq
         assert_eq!(small, small);
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 9aeee4ba7b7..f078cd3bda3 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -749,7 +749,7 @@ pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
 pub fn dedup<T:Eq>(v: &mut ~[T]) {
     unsafe {
         if v.len() < 1 { return; }
-        let mut last_written = 0, next_to_read = 1;
+        let mut (last_written, next_to_read) = (0, 1);
         do as_const_buf(*v) |p, ln| {
             // We have a mutable reference to v, so we can make arbitrary
             // changes. (cf. push and pop)
@@ -1365,7 +1365,7 @@ pub fn bsearch_elem<T:TotalOrd>(v: &[T], x: &T) -> Option<uint> {
  * Convert a vector of pairs into a pair of vectors, by reference. As unzip().
  */
 pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
-    let mut ts = ~[], us = ~[];
+    let mut (ts, us) = (~[], ~[]);
     for each(v) |p| {
         let (t, u) = *p;
         ts.push(t);
@@ -1383,7 +1383,7 @@ pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
  * of the i-th tuple of the input vector.
  */
 pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
-    let mut ts = ~[], us = ~[];
+    let mut (ts, us) = (~[], ~[]);
     do consume(v) |_i, p| {
         let (t, u) = p;
         ts.push(t);