Skip to content

Commit 4757631

Browse files
committed
Remove and replace cond! Closes #9282.
1 parent adb638f commit 4757631

File tree

8 files changed

+55
-137
lines changed

8 files changed

+55
-137
lines changed

src/libextra/num/bigint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ impl TotalOrd for BigUint {
115115
if s_len > o_len { return Greater; }
116116

117117
for (&self_i, &other_i) in self.data.rev_iter().zip(other.data.rev_iter()) {
118-
cond!((self_i < other_i) { return Less; }
119-
(self_i > other_i) { return Greater; })
118+
if self_i < other_i { return Less; }
119+
if self_i > other_i { return Greater; }
120120
}
121121
return Equal;
122122
}

src/libstd/char.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
281281
// avoid calling str::to_str_radix because we don't really need to allocate
282282
// here.
283283
f('\\');
284-
let pad = cond!(
285-
(c <= '\xff') { f('x'); 2 }
286-
(c <= '\uffff') { f('u'); 4 }
287-
_ { f('U'); 8 }
288-
);
284+
let pad = match () {
285+
_ if c <= '\xff' => { f('x'); 2 }
286+
_ if c <= '\uffff' => { f('u'); 4 }
287+
_ => { f('U'); 8 }
288+
};
289289
for offset in range_step::<i32>(4 * (pad - 1), -1, -4) {
290290
unsafe {
291291
match ((c as i32) >> offset) & 0xf {
@@ -329,13 +329,13 @@ pub fn len_utf8_bytes(c: char) -> uint {
329329
static MAX_FOUR_B: uint = 2097152u;
330330

331331
let code = c as uint;
332-
cond!(
333-
(code < MAX_ONE_B) { 1u }
334-
(code < MAX_TWO_B) { 2u }
335-
(code < MAX_THREE_B) { 3u }
336-
(code < MAX_FOUR_B) { 4u }
337-
_ { fail!("invalid character!") }
338-
)
332+
match () {
333+
_ if code < MAX_ONE_B => 1u,
334+
_ if code < MAX_TWO_B => 2u,
335+
_ if code < MAX_THREE_B => 3u,
336+
_ if code < MAX_FOUR_B => 4u,
337+
_ => fail!("invalid character!"),
338+
}
339339
}
340340

341341
impl ToStr for char {

src/libstd/num/f32.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,35 +206,35 @@ impl Orderable for f32 {
206206
/// Returns `NaN` if either of the numbers are `NaN`.
207207
#[inline]
208208
fn min(&self, other: &f32) -> f32 {
209-
cond!(
210-
(self.is_NaN()) { *self }
211-
(other.is_NaN()) { *other }
212-
(*self < *other) { *self }
213-
_ { *other }
214-
)
209+
match () {
210+
_ if self.is_NaN() => *self,
211+
_ if other.is_NaN() => *other,
212+
_ if *self < *other => *self,
213+
_ => *other,
214+
}
215215
}
216216

217217
/// Returns `NaN` if either of the numbers are `NaN`.
218218
#[inline]
219219
fn max(&self, other: &f32) -> f32 {
220-
cond!(
221-
(self.is_NaN()) { *self }
222-
(other.is_NaN()) { *other }
223-
(*self > *other) { *self }
224-
_ { *other }
225-
)
220+
match () {
221+
_ if self.is_NaN() => *self,
222+
_ if other.is_NaN() => *other,
223+
_ if *self > *other => *self,
224+
_ => *other,
225+
}
226226
}
227227

228228
/// Returns the number constrained within the range `mn <= self <= mx`.
229229
/// If any of the numbers are `NaN` then `NaN` is returned.
230230
#[inline]
231231
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
232-
cond!(
233-
(self.is_NaN()) { *self }
234-
(!(*self <= *mx)) { *mx }
235-
(!(*self >= *mn)) { *mn }
236-
_ { *self }
237-
)
232+
match () {
233+
_ if self.is_NaN() => *self,
234+
_ if !(*self <= *mx) => *mx,
235+
_ if !(*self >= *mn) => *mn,
236+
_ => *self,
237+
}
238238
}
239239
}
240240

src/libstd/num/f64.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,35 +229,35 @@ impl Orderable for f64 {
229229
/// Returns `NaN` if either of the numbers are `NaN`.
230230
#[inline]
231231
fn min(&self, other: &f64) -> f64 {
232-
cond!(
233-
(self.is_NaN()) { *self }
234-
(other.is_NaN()) { *other }
235-
(*self < *other) { *self }
236-
_ { *other }
237-
)
232+
match () {
233+
_ if self.is_NaN() => *self,
234+
_ if other.is_NaN() => *other,
235+
_ if *self < *other => *self,
236+
_ => *other,
237+
}
238238
}
239239

240240
/// Returns `NaN` if either of the numbers are `NaN`.
241241
#[inline]
242242
fn max(&self, other: &f64) -> f64 {
243-
cond!(
244-
(self.is_NaN()) { *self }
245-
(other.is_NaN()) { *other }
246-
(*self > *other) { *self }
247-
_ { *other }
248-
)
243+
match () {
244+
_ if self.is_NaN() => *self,
245+
_ if other.is_NaN() => *other,
246+
_ if *self > *other => *self,
247+
_ => *other,
248+
}
249249
}
250250

251251
/// Returns the number constrained within the range `mn <= self <= mx`.
252252
/// If any of the numbers are `NaN` then `NaN` is returned.
253253
#[inline]
254254
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
255-
cond!(
256-
(self.is_NaN()) { *self }
257-
(!(*self <= *mx)) { *mx }
258-
(!(*self >= *mn)) { *mn }
259-
_ { *self }
260-
)
255+
match () {
256+
_ if self.is_NaN() => *self,
257+
_ if !(*self <= *mx) => *mx,
258+
_ if !(*self >= *mn) => *mn,
259+
_ => *self,
260+
}
261261
}
262262
}
263263

src/libstd/num/uint_macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ impl Orderable for $T {
7070
/// Returns the number constrained within the range `mn <= self <= mx`.
7171
#[inline]
7272
fn clamp(&self, mn: &$T, mx: &$T) -> $T {
73-
cond!(
74-
(*self > *mx) { *mx }
75-
(*self < *mn) { *mn }
76-
_ { *self }
77-
)
73+
match () {
74+
_ if (*self > *mx) => *mx,
75+
_ if (*self < *mn) => *mn,
76+
_ => *self,
77+
}
7878
}
7979
}
8080

src/libsyntax/ext/expand.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -898,42 +898,6 @@ pub fn std_macros() -> @str {
898898
}
899899
)
900900

901-
//
902-
// A scheme-style conditional that helps to improve code clarity in some instances when
903-
// the `if`, `else if`, and `else` keywords obscure predicates undesirably.
904-
//
905-
// # Example
906-
//
907-
// ~~~
908-
// let clamped =
909-
// if x > mx { mx }
910-
// else if x < mn { mn }
911-
// else { x };
912-
// ~~~
913-
//
914-
// Using `cond!`, the above could be written as:
915-
//
916-
// ~~~
917-
// let clamped = cond!(
918-
// (x > mx) { mx }
919-
// (x < mn) { mn }
920-
// _ { x }
921-
// );
922-
// ~~~
923-
//
924-
// The optional default case is denoted by `_`.
925-
//
926-
macro_rules! cond (
927-
( $(($pred:expr) $body:block)+ _ $default:block ) => (
928-
$(if $pred $body else)+
929-
$default
930-
);
931-
// for if the default case was ommitted
932-
( $(($pred:expr) $body:block)+ ) => (
933-
$(if $pred $body)else+
934-
);
935-
)
936-
937901
// NOTE(acrichto): start removing this after the next snapshot
938902
macro_rules! printf (
939903
($arg:expr) => (

src/test/run-pass/cond-macro-no-default.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/test/run-pass/cond-macro.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)