Skip to content

Remove and replace cond! Closes #9282. #9291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 12 additions & 12 deletions src/libstd/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 18 additions & 18 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libstd/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

Expand Down
36 changes: 0 additions & 36 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,42 +898,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) => (
Expand Down
23 changes: 0 additions & 23 deletions src/test/run-pass/cond-macro-no-default.rs

This file was deleted.

23 changes: 0 additions & 23 deletions src/test/run-pass/cond-macro.rs

This file was deleted.