Skip to content

Commit 608ca03

Browse files
committed
---
yaml --- r: 61283 b: refs/heads/try c: b9824e1 h: refs/heads/master i: 61281: 4062198 61279: 0478fe4 v: v3
1 parent 6a86270 commit 608ca03

File tree

8 files changed

+112
-36
lines changed

8 files changed

+112
-36
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
5-
refs/heads/try: be062db808f34983d6039d0a12c0110cba2b730e
5+
refs/heads/try: b9824e18c2b02d74bd1bf646fea5f05477ca5071
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/flatpipes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ mod test {
639639
use core::io::BytesWriter;
640640

641641
#[test]
642+
#[ignore(reason = "ebml failure")]
642643
fn test_serializing_memory_stream() {
643644
let writer = BytesWriter();
644645
let chan = serial::writer_chan(writer);
@@ -671,6 +672,7 @@ mod test {
671672
}
672673

673674
#[test]
675+
#[ignore(reason = "ebml failure")]
674676
fn test_serializing_boxes() {
675677
let (port, chan) = serial::pipe_stream();
676678

branches/try/src/libstd/fun_treemap.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,40 @@ enum TreeNode<K, V> {
3333
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
3434

3535
/// Insert a value into the map
36-
pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V)
37-
-> Treemap<K, V> {
36+
pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
3837
@match m {
39-
@Empty => Node(@k, @v, @Empty, @Empty),
40-
@Node(@copy kk, vv, left, right) => {
41-
if k < kk {
42-
Node(@kk, vv, insert(left, k, v), right)
43-
} else if k == kk {
44-
Node(@kk, @v, left, right)
45-
} else { Node(@kk, vv, left, insert(right, k, v)) }
46-
}
47-
}
38+
@Empty => Node(@k, @v, @Empty, @Empty),
39+
@Node(@copy kk, vv, left, right) => cond!(
40+
| k < kk { Node(@kk, vv, insert(left, k, v), right) }
41+
| k == kk { Node(@kk, @v, left, right) }
42+
_ { Node(@kk, vv, left, insert(right, k, v)) }
43+
)
44+
}
4845
}
4946

5047
/// Find a value based on the key
5148
pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
5249
match *m {
53-
Empty => None,
54-
Node(@ref kk, @copy v, left, right) => {
55-
if k == *kk {
56-
Some(v)
57-
} else if k < *kk { find(left, k) } else { find(right, k) }
58-
}
50+
Empty => None,
51+
Node(@ref kk, @copy v, left, right) => cond!(
52+
| k == *kk { Some(v) }
53+
| k < *kk { find(left, k) }
54+
_ { find(right, k) }
55+
)
5956
}
6057
}
6158

6259
/// Visit all pairs in the map in order.
6360
pub fn traverse<K, V: Copy>(m: Treemap<K, V>, f: &fn(&K, &V)) {
6461
match *m {
65-
Empty => (),
66-
/*
67-
Previously, this had what looked like redundant
68-
matches to me, so I changed it. but that may be a
69-
de-optimization -- tjc
70-
*/
71-
Node(@ref k, @ref v, left, right) => {
72-
traverse(left, f);
73-
f(k, v);
74-
traverse(right, f);
75-
}
62+
Empty => (),
63+
// Previously, this had what looked like redundant
64+
// matches to me, so I changed it. but that may be a
65+
// de-optimization -- tjc
66+
Node(@ref k, @ref v, left, right) => {
67+
traverse(left, f);
68+
f(k, v);
69+
traverse(right, f);
70+
}
7671
}
7772
}

branches/try/src/libstd/std.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub mod flatpipes;
6363

6464
pub mod bitv;
6565
pub mod deque;
66+
#[cfg(not(stage0))]
6667
pub mod fun_treemap;
6768
pub mod list;
6869
pub mod priority_queue;

branches/try/src/libsyntax/ext/expand.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,41 @@ pub fn core_macros() -> ~str {
542542
}
543543
)
544544

545-
545+
//
546+
// A scheme-style conditional that helps to improve code clarity in some instances when
547+
// the `if`, `else if`, and `else` keywords obscure predicates undesirably.
548+
//
549+
// # Example
550+
//
551+
// ~~~
552+
// let clamped =
553+
// if x > mx { mx }
554+
// else if x < mn { mn }
555+
// else { x };
556+
// ~~~
557+
//
558+
// Using `cond!`, the above could be written as:
559+
//
560+
// ~~~
561+
// let clamped = cond!(
562+
// | x > mx { mx }
563+
// | x < mn { mn }
564+
// _ { x }
565+
// );
566+
// ~~~
567+
//
568+
// The optional default case is denoted by `_`.
569+
//
570+
macro_rules! cond (
571+
($( | $pred:expr $body:block)+ _ $default:block ) => (
572+
$(if $pred $body else)+
573+
$default
574+
);
575+
// for if the default case was ommitted
576+
( $( | $pred:expr $body:block )+ ) => (
577+
$(if $pred $body)else+
578+
);
579+
)
546580
}";
547581
}
548582

branches/try/src/test/compile-fail/unsafe-fn-autoderef.rs

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

12-
struct Rec {
13-
f: int
14-
}
15-
16-
fn f(p: *Rec) -> int {
12+
// xfail-test
13+
type rec = {f: int};
14+
fn f(p: *rec) -> int {
1715

1816
// Test that * ptrs do not autoderef. There is a deeper reason for
1917
// prohibiting this, beyond making unsafe things annoying (which doesn't
@@ -27,7 +25,7 @@ fn f(p: *Rec) -> int {
2725
// are prohibited by various checks, such as that the enum is
2826
// instantiable and so forth).
2927

30-
return p.f; //~ ERROR attempted access of field `f` on type `*Rec`
28+
return p.f; //~ ERROR attempted access of field `f` on type `*rec`
3129
}
3230

3331
fn main() {
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:Copy + 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+
}
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:Copy + 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+
}

0 commit comments

Comments
 (0)