Skip to content

Commit 3fbd1ab

Browse files
committed
---
yaml --- r: 81653 b: refs/heads/master c: 10d26f8 h: refs/heads/master i: 81651: 9f34f32 v: v3
1 parent 51a7a48 commit 3fbd1ab

File tree

14 files changed

+160
-67
lines changed

14 files changed

+160
-67
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 47576313695170013cfe07d57e81c2e879a14c14
2+
refs/heads/master: 10d26f8daf52ca60b785712682c1962e98954fd9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729

trunk/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-
if self_i < other_i { return Less; }
119-
if self_i > other_i { return Greater; }
118+
cond!((self_i < other_i) { return Less; }
119+
(self_i > other_i) { return Greater; })
120120
}
121121
return Equal;
122122
}

trunk/src/librustc/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn version(argv0: &str) {
134134

135135
pub fn usage(argv0: &str) {
136136
let message = fmt!("Usage: %s [OPTIONS] INPUT", argv0);
137-
printfln!("%s\
137+
printfln!("%s\n\
138138
Additional help:
139139
-W help Print 'lint' options and default settings
140140
-Z help Print internal options for debugging rustc\n",

trunk/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 = match () {
285-
_ if c <= '\xff' => { f('x'); 2 }
286-
_ if c <= '\uffff' => { f('u'); 4 }
287-
_ => { f('U'); 8 }
288-
};
284+
let pad = cond!(
285+
(c <= '\xff') { f('x'); 2 }
286+
(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-
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-
}
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+
)
339339
}
340340

341341
impl ToStr for char {

trunk/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-
match () {
210-
_ if self.is_NaN() => *self,
211-
_ if other.is_NaN() => *other,
212-
_ if *self < *other => *self,
213-
_ => *other,
214-
}
209+
cond!(
210+
(self.is_NaN()) { *self }
211+
(other.is_NaN()) { *other }
212+
(*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-
match () {
221-
_ if self.is_NaN() => *self,
222-
_ if other.is_NaN() => *other,
223-
_ if *self > *other => *self,
224-
_ => *other,
225-
}
220+
cond!(
221+
(self.is_NaN()) { *self }
222+
(other.is_NaN()) { *other }
223+
(*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-
match () {
233-
_ if self.is_NaN() => *self,
234-
_ if !(*self <= *mx) => *mx,
235-
_ if !(*self >= *mn) => *mn,
236-
_ => *self,
237-
}
232+
cond!(
233+
(self.is_NaN()) { *self }
234+
(!(*self <= *mx)) { *mx }
235+
(!(*self >= *mn)) { *mn }
236+
_ { *self }
237+
)
238238
}
239239
}
240240

trunk/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-
match () {
233-
_ if self.is_NaN() => *self,
234-
_ if other.is_NaN() => *other,
235-
_ if *self < *other => *self,
236-
_ => *other,
237-
}
232+
cond!(
233+
(self.is_NaN()) { *self }
234+
(other.is_NaN()) { *other }
235+
(*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-
match () {
244-
_ if self.is_NaN() => *self,
245-
_ if other.is_NaN() => *other,
246-
_ if *self > *other => *self,
247-
_ => *other,
248-
}
243+
cond!(
244+
(self.is_NaN()) { *self }
245+
(other.is_NaN()) { *other }
246+
(*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-
match () {
256-
_ if self.is_NaN() => *self,
257-
_ if !(*self <= *mx) => *mx,
258-
_ if !(*self >= *mn) => *mn,
259-
_ => *self,
260-
}
255+
cond!(
256+
(self.is_NaN()) { *self }
257+
(!(*self <= *mx)) { *mx }
258+
(!(*self >= *mn)) { *mn }
259+
_ { *self }
260+
)
261261
}
262262
}
263263

trunk/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-
match () {
74-
_ if (*self > *mx) => *mx,
75-
_ if (*self < *mn) => *mn,
76-
_ => *self,
77-
}
73+
cond!(
74+
(*self > *mx) { *mx }
75+
(*self < *mn) { *mn }
76+
_ { *self }
77+
)
7878
}
7979
}
8080

trunk/src/libsyntax/ext/expand.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,42 @@ 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+
901937
// NOTE(acrichto): start removing this after the next snapshot
902938
macro_rules! printf (
903939
($arg:expr) => (

trunk/src/libsyntax/print/pp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub fn mk_printer(out: @io::Writer, linewidth: uint) -> @mut Printer {
243243
* the entire buffered window, but can't output anything until the size is >=
244244
* 0 (sizes are set to negative while they're pending calculation).
245245
*
246-
* So SCAN takeks input and buffers tokens and pending calculations, while
246+
* So SCAN takes input and buffers tokens and pending calculations, while
247247
* PRINT gobbles up completed calculations and tokens from the buffer. The
248248
* theory is that the two can never get more than 3N tokens apart, because
249249
* once there's "obviously" too much data to fit on a line, in a size

trunk/src/libsyntax/print/pprust.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,15 +1535,15 @@ fn print_path_(s: @ps,
15351535

15361536
print_ident(s, segment.identifier);
15371537

1538-
if segment.lifetime.is_some() || !segment.types.is_empty() {
1539-
// If this is the last segment, print the bounds.
1540-
if i == path.segments.len() - 1 {
1541-
match *opt_bounds {
1542-
None => {}
1543-
Some(ref bounds) => print_bounds(s, bounds, true),
1544-
}
1538+
// If this is the last segment, print the bounds.
1539+
if i == path.segments.len() - 1 {
1540+
match *opt_bounds {
1541+
None => {}
1542+
Some(ref bounds) => print_bounds(s, bounds, true),
15451543
}
1544+
}
15461545

1546+
if segment.lifetime.is_some() || !segment.types.is_empty() {
15471547
if colons_before_params {
15481548
word(s.s, "::")
15491549
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// pp-exact
2+
3+
trait Tr { }
4+
impl Tr for int;
5+
6+
fn foo(x: ~Tr: Freeze) -> ~Tr: Freeze { x }
7+
8+
fn main() {
9+
let x: ~Tr: Freeze;
10+
11+
~1 as ~Tr: Freeze;
12+
}
13+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn clamp<T:Ord + Signed>(x: T, mn: T, mx: T) -> T {
12+
cond!(
13+
(x > mx) { return mx; }
14+
(x < mn) { return mn; }
15+
)
16+
return x;
17+
}
18+
19+
fn main() {
20+
assert_eq!(clamp(1, 2, 4), 2);
21+
assert_eq!(clamp(8, 2, 4), 4);
22+
assert_eq!(clamp(3, 2, 4), 3);
23+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn clamp<T:Ord + Signed>(x: T, mn: T, mx: T) -> T {
12+
cond!(
13+
(x > mx) { mx }
14+
(x < mn) { mn }
15+
_ { x }
16+
)
17+
}
18+
19+
fn main() {
20+
assert_eq!(clamp(1, 2, 4), 2);
21+
assert_eq!(clamp(8, 2, 4), 4);
22+
assert_eq!(clamp(3, 2, 4), 3);
23+
}

trunk/src/test/run-pass/issue-7673-cast-generically-implemented-trait.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-pretty #9253 pretty printer doesn't preserve the bounds on trait objects
12-
1311
/*
1412
1513
#7673 Polymorphically creating traits barely works

0 commit comments

Comments
 (0)