about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libextra/num/bigint.rs4
-rw-r--r--src/libstd/borrow.rs16
-rw-r--r--src/libstd/char.rs24
-rw-r--r--src/libstd/num/f32.rs36
-rw-r--r--src/libstd/num/f64.rs36
-rw-r--r--src/libstd/num/uint_macros.rs10
-rw-r--r--src/libsyntax/ext/expand.rs36
-rw-r--r--src/test/run-pass/cond-macro-no-default.rs23
-rw-r--r--src/test/run-pass/cond-macro.rs23
9 files changed, 70 insertions, 138 deletions
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs
index 039694f5881..936efed94e4 100644
--- a/src/libextra/num/bigint.rs
+++ b/src/libextra/num/bigint.rs
@@ -115,8 +115,8 @@ impl TotalOrd for BigUint {
         if s_len > o_len { return Greater;  }
 
         for (&self_i, &other_i) in self.data.rev_iter().zip(other.data.rev_iter()) {
-            cond!((self_i < other_i) { return Less; }
-                  (self_i > other_i) { return Greater; })
+            if self_i < other_i { return Less; }
+            if self_i > other_i { return Greater; }
         }
         return Equal;
     }
diff --git a/src/libstd/borrow.rs b/src/libstd/borrow.rs
index 6c3d4c5f1fb..0626b3fc618 100644
--- a/src/libstd/borrow.rs
+++ b/src/libstd/borrow.rs
@@ -22,7 +22,7 @@ pub fn to_uint<T>(thing: &T) -> uint {
 /// Determine if two borrowed pointers point to the same thing.
 #[inline]
 pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
-    to_uint(thing) == to_uint(other)
+    (thing as *T) == (other as *T)
 }
 
 // Equality for region pointers
@@ -70,3 +70,17 @@ impl<'self, T: TotalEq> TotalEq for &'self T {
     #[inline]
     fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::ref_eq;
+
+    #[test]
+    fn test_ref_eq() {
+        let x = 1;
+        let y = 1;
+
+        assert!(ref_eq(&x, &x));
+        assert!(!ref_eq(&x, &y));
+    }
+}
diff --git a/src/libstd/char.rs b/src/libstd/char.rs
index 911d883f88a..431fc27a202 100644
--- a/src/libstd/char.rs
+++ b/src/libstd/char.rs
@@ -281,11 +281,11 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
     // avoid calling str::to_str_radix because we don't really need to allocate
     // here.
     f('\\');
-    let pad = cond!(
-        (c <= '\xff')   { f('x'); 2 }
-        (c <= '\uffff') { f('u'); 4 }
-        _               { f('U'); 8 }
-    );
+    let pad = match () {
+        _ if c <= '\xff'    => { f('x'); 2 }
+        _ if c <= '\uffff'  => { f('u'); 4 }
+        _                   => { f('U'); 8 }
+    };
     for offset in range_step::<i32>(4 * (pad - 1), -1, -4) {
         unsafe {
             match ((c as i32) >> offset) & 0xf {
@@ -329,13 +329,13 @@ pub fn len_utf8_bytes(c: char) -> uint {
     static MAX_FOUR_B:  uint = 2097152u;
 
     let code = c as uint;
-    cond!(
-        (code < MAX_ONE_B)   { 1u }
-        (code < MAX_TWO_B)   { 2u }
-        (code < MAX_THREE_B) { 3u }
-        (code < MAX_FOUR_B)  { 4u }
-        _ { fail!("invalid character!") }
-    )
+    match () {
+        _ if code < MAX_ONE_B   => 1u,
+        _ if code < MAX_TWO_B   => 2u,
+        _ if code < MAX_THREE_B => 3u,
+        _ if code < MAX_FOUR_B  => 4u,
+        _                       => fail!("invalid character!"),
+    }
 }
 
 impl ToStr for char {
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs
index 1bb488d0278..2787e028645 100644
--- a/src/libstd/num/f32.rs
+++ b/src/libstd/num/f32.rs
@@ -206,35 +206,35 @@ impl Orderable for f32 {
     /// Returns `NaN` if either of the numbers are `NaN`.
     #[inline]
     fn min(&self, other: &f32) -> f32 {
-        cond!(
-            (self.is_NaN())  { *self  }
-            (other.is_NaN()) { *other }
-            (*self < *other) { *self  }
-            _                { *other }
-        )
+        match () {
+            _ if self.is_NaN()  => *self,
+            _ if other.is_NaN() => *other,
+            _ if *self < *other => *self,
+            _                   => *other,
+        }
     }
 
     /// Returns `NaN` if either of the numbers are `NaN`.
     #[inline]
     fn max(&self, other: &f32) -> f32 {
-        cond!(
-            (self.is_NaN())  { *self  }
-            (other.is_NaN()) { *other }
-            (*self > *other) { *self  }
-            _                { *other }
-        )
+        match () {
+            _ if self.is_NaN()  => *self,
+            _ if other.is_NaN() => *other,
+            _ if *self > *other => *self,
+            _                   => *other,
+        }
     }
 
     /// Returns the number constrained within the range `mn <= self <= mx`.
     /// If any of the numbers are `NaN` then `NaN` is returned.
     #[inline]
     fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
-        cond!(
-            (self.is_NaN())   { *self }
-            (!(*self <= *mx)) { *mx   }
-            (!(*self >= *mn)) { *mn   }
-            _                 { *self }
-        )
+        match () {
+            _ if self.is_NaN()   => *self,
+            _ if !(*self <= *mx) => *mx,
+            _ if !(*self >= *mn) => *mn,
+            _                    => *self,
+        }
     }
 }
 
diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs
index 604eac0a0a7..afc22ec212b 100644
--- a/src/libstd/num/f64.rs
+++ b/src/libstd/num/f64.rs
@@ -229,35 +229,35 @@ impl Orderable for f64 {
     /// Returns `NaN` if either of the numbers are `NaN`.
     #[inline]
     fn min(&self, other: &f64) -> f64 {
-        cond!(
-            (self.is_NaN())  { *self  }
-            (other.is_NaN()) { *other }
-            (*self < *other) { *self  }
-            _                { *other }
-        )
+        match () {
+            _ if self.is_NaN()  => *self,
+            _ if other.is_NaN() => *other,
+            _ if *self < *other => *self,
+            _                   => *other,
+        }
     }
 
     /// Returns `NaN` if either of the numbers are `NaN`.
     #[inline]
     fn max(&self, other: &f64) -> f64 {
-        cond!(
-            (self.is_NaN())  { *self  }
-            (other.is_NaN()) { *other }
-            (*self > *other) { *self  }
-            _                { *other }
-        )
+        match () {
+            _ if self.is_NaN()  => *self,
+            _ if other.is_NaN() => *other,
+            _ if *self > *other => *self,
+            _                   => *other,
+        }
     }
 
     /// Returns the number constrained within the range `mn <= self <= mx`.
     /// If any of the numbers are `NaN` then `NaN` is returned.
     #[inline]
     fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
-        cond!(
-            (self.is_NaN())   { *self }
-            (!(*self <= *mx)) { *mx   }
-            (!(*self >= *mn)) { *mn   }
-            _                 { *self }
-        )
+        match () {
+            _ if self.is_NaN()   => *self,
+            _ if !(*self <= *mx) => *mx,
+            _ if !(*self >= *mn) => *mn,
+            _                    => *self,
+        }
     }
 }
 
diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs
index 0a9c912a6e2..7cd1be7ab74 100644
--- a/src/libstd/num/uint_macros.rs
+++ b/src/libstd/num/uint_macros.rs
@@ -70,11 +70,11 @@ impl Orderable for $T {
     /// Returns the number constrained within the range `mn <= self <= mx`.
     #[inline]
     fn clamp(&self, mn: &$T, mx: &$T) -> $T {
-        cond!(
-            (*self > *mx) { *mx   }
-            (*self < *mn) { *mn   }
-            _             { *self }
-        )
+        match () {
+            _ if (*self > *mx) => *mx,
+            _ if (*self < *mn) => *mn,
+            _                  => *self,
+        }
     }
 }
 
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 7254e8e775a..0bee7895420 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -894,42 +894,6 @@ pub fn std_macros() -> @str {
         }
     )
 
-    //
-    // A scheme-style conditional that helps to improve code clarity in some instances when
-    // the `if`, `else if`, and `else` keywords obscure predicates undesirably.
-    //
-    // # Example
-    //
-    // ~~~
-    // let clamped =
-    //     if x > mx { mx }
-    //     else if x < mn { mn }
-    //     else { x };
-    // ~~~
-    //
-    // Using `cond!`, the above could be written as:
-    //
-    // ~~~
-    // let clamped = cond!(
-    //     (x > mx) { mx }
-    //     (x < mn) { mn }
-    //     _        { x  }
-    // );
-    // ~~~
-    //
-    // The optional default case is denoted by `_`.
-    //
-    macro_rules! cond (
-        ( $(($pred:expr) $body:block)+ _ $default:block ) => (
-            $(if $pred $body else)+
-            $default
-        );
-        // for if the default case was ommitted
-        ( $(($pred:expr) $body:block)+ ) => (
-            $(if $pred $body)else+
-        );
-    )
-
     // NOTE(acrichto): start removing this after the next snapshot
     macro_rules! printf (
         ($arg:expr) => (
diff --git a/src/test/run-pass/cond-macro-no-default.rs b/src/test/run-pass/cond-macro-no-default.rs
deleted file mode 100644
index 8bd1a772e55..00000000000
--- a/src/test/run-pass/cond-macro-no-default.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn clamp<T:Ord + Signed>(x: T, mn: T, mx: T) -> T {
-    cond!(
-        (x > mx) { return mx; }
-        (x < mn) { return mn; }
-    )
-    return x;
-}
-
-fn main() {
-    assert_eq!(clamp(1, 2, 4), 2);
-    assert_eq!(clamp(8, 2, 4), 4);
-    assert_eq!(clamp(3, 2, 4), 3);
-}
diff --git a/src/test/run-pass/cond-macro.rs b/src/test/run-pass/cond-macro.rs
deleted file mode 100644
index 61a51b67261..00000000000
--- a/src/test/run-pass/cond-macro.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn clamp<T:Ord + Signed>(x: T, mn: T, mx: T) -> T {
-    cond!(
-        (x > mx) { mx }
-        (x < mn) { mn }
-        _        { x  }
-    )
-}
-
-fn main() {
-    assert_eq!(clamp(1, 2, 4), 2);
-    assert_eq!(clamp(8, 2, 4), 4);
-    assert_eq!(clamp(3, 2, 4), 3);
-}