Skip to content

Commit 13db650

Browse files
committed
---
yaml --- r: 55170 b: refs/heads/snap-stage3 c: a6eaa3b h: refs/heads/master v: v3
1 parent 285f2e4 commit 13db650

File tree

14 files changed

+276
-2
lines changed

14 files changed

+276
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9455eaf77bef8f225e146e61107d26010f137b51
4+
refs/heads/snap-stage3: a6eaa3bbb490b01c21864adc41e12eafb98a3c32
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! Utilities for manipulating the char type
1212
13+
#[cfg(notest)]
1314
use cmp::Ord;
1415
use option::{None, Option, Some};
1516
use str;

branches/snap-stage3/src/libcore/iter.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ much easier to implement.
4141
4242
*/
4343

44+
use cmp::Ord;
45+
use option::{Option, Some, None};
46+
4447
pub trait Times {
4548
fn times(&self, it: &fn() -> bool);
4649
}
@@ -104,6 +107,78 @@ pub fn all<T>(predicate: &fn(T) -> bool, iter: &fn(f: &fn(T) -> bool)) -> bool {
104107
true
105108
}
106109

110+
/**
111+
* Return the first element where `predicate` returns `true`. Return `None` if no element is found.
112+
*
113+
* # Example:
114+
*
115+
* ~~~~
116+
* let xs = ~[1u, 2, 3, 4, 5, 6];
117+
* assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.each(f)).unwrap(), 4);
118+
* ~~~~
119+
*/
120+
#[inline(always)]
121+
pub fn find<T>(predicate: &fn(&T) -> bool, iter: &fn(f: &fn(T) -> bool)) -> Option<T> {
122+
for iter |x| {
123+
if predicate(&x) {
124+
return Some(x);
125+
}
126+
}
127+
None
128+
}
129+
130+
/**
131+
* Return the largest item yielded by an iterator. Return `None` if the iterator is empty.
132+
*
133+
* # Example:
134+
*
135+
* ~~~~
136+
* let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
137+
* assert_eq!(max(|f| xs.each(f)).unwrap(), &15);
138+
* ~~~~
139+
*/
140+
#[inline]
141+
pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool)) -> Option<T> {
142+
let mut result = None;
143+
for iter |x| {
144+
match result {
145+
Some(ref mut y) => {
146+
if x > *y {
147+
*y = x;
148+
}
149+
}
150+
None => result = Some(x)
151+
}
152+
}
153+
result
154+
}
155+
156+
/**
157+
* Return the smallest item yielded by an iterator. Return `None` if the iterator is empty.
158+
*
159+
* # Example:
160+
*
161+
* ~~~~
162+
* let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
163+
* assert_eq!(max(|f| xs.each(f)).unwrap(), &-5);
164+
* ~~~~
165+
*/
166+
#[inline]
167+
pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool)) -> Option<T> {
168+
let mut result = None;
169+
for iter |x| {
170+
match result {
171+
Some(ref mut y) => {
172+
if x < *y {
173+
*y = x;
174+
}
175+
}
176+
None => result = Some(x)
177+
}
178+
}
179+
result
180+
}
181+
107182
#[cfg(test)]
108183
mod tests {
109184
use super::*;
@@ -128,4 +203,22 @@ mod tests {
128203
assert!(all(|x: uint| x < 6, |f| uint::range(1, 6, f)));
129204
assert!(!all(|x: uint| x < 5, |f| uint::range(1, 6, f)));
130205
}
206+
207+
#[test]
208+
fn test_find() {
209+
let xs = ~[1u, 2, 3, 4, 5, 6];
210+
assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.each(f)).unwrap(), 4);
211+
}
212+
213+
#[test]
214+
fn test_max() {
215+
let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
216+
assert_eq!(max(|f| xs.each(f)).unwrap(), &15);
217+
}
218+
219+
#[test]
220+
fn test_min() {
221+
let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
222+
assert_eq!(min(|f| xs.each(f)).unwrap(), &-5);
223+
}
131224
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2012 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+
#[link(name = "issue2196a", vers = "0.1")];
12+
#[crate_type = "lib"];
13+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 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+
#[link(name = "issue2196b", vers = "0.1")];
12+
#[crate_type = "lib"];
13+
14+
use a(name = "issue2196a");
15+
16+
type d = str;
17+
impl d for d { }
18+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2012 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+
#[link(name = "issue2196c", vers = "0.1")];
12+
#[crate_type = "lib"];
13+
14+
use b(name = "issue2196b");
15+
#[path = "issue-2196-d.rs"]
16+
mod d;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2012 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+
use b::d;
12+
13+
type t = uint;
14+

branches/snap-stage3/src/test/auxiliary/issue-2196-d.rs

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 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+
// exec-env:RUST_CC_ZEAL=1
12+
// xfail-test
13+
14+
pub fn main() {
15+
error!("%?", os::getenv(~"RUST_CC_ZEAL"));
16+
let _x = @{a: @10, b: ~true};
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2012 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+
// exec-env:RUST_CC_ZEAL=1
12+
13+
enum maybe_pointy {
14+
none,
15+
p(@mut Pointy)
16+
}
17+
18+
struct Pointy {
19+
a : maybe_pointy,
20+
f : @fn()->(),
21+
}
22+
23+
fn empty_pointy() -> @mut Pointy {
24+
return @mut Pointy{
25+
a : none,
26+
f : || {},
27+
}
28+
}
29+
30+
pub fn main() {
31+
let v = ~[empty_pointy(), empty_pointy()];
32+
v[0].a = p(v[0]);
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012 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+
// xfail-test
12+
// aux-build:issue-2196-a.rs
13+
// aux-build:issue-2196-b.rs
14+
// aux-build:issue-2196-c.rc
15+
16+
use c(name = "issue2196c");
17+
use c::t;
18+
19+
pub fn main() { }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 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+
// xfail-test
12+
enum pat { pat_ident(Option<uint>) }
13+
14+
fn f(pat: pat) -> bool { true }
15+
16+
fn num_bindings(pat: pat) -> uint {
17+
match pat {
18+
pat_ident(_) if f(pat) { 0 }
19+
pat_ident(None) { 1 }
20+
pat_ident(Some(sub)) { sub }
21+
}
22+
}
23+
24+
pub fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2012 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+
// xfail-test
12+
type IMap<K:Copy,V:Copy> = ~[(K, V)];
13+
14+
trait ImmutableMap<K:Copy,V:Copy>
15+
{
16+
fn contains_key(key: K) -> bool;
17+
}
18+
19+
impl<K:Copy,V:Copy> IMap<K, V> : ImmutableMap<K, V>
20+
{
21+
fn contains_key(key: K) -> bool {
22+
vec::find(self, |e| {e.first() == key}).is_some()
23+
}
24+
}
25+
26+
pub fn main() {}

branches/snap-stage3/src/test/run-pass/issue-3979-generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Positioned<int> for Point {
3232
}
3333
}
3434

35-
impl Movable<int, int> for Point;
35+
impl Point: Movable<int, int>;
3636

3737
pub fn main() {
3838
let p = Point{ x: 1, y: 2};

0 commit comments

Comments
 (0)