Skip to content

Commit acd85ba

Browse files
committed
---
yaml --- r: 114315 b: refs/heads/master c: 6291955 h: refs/heads/master i: 114313: ba1ef99 114311: 6a02453 v: v3
1 parent 6c26c55 commit acd85ba

File tree

11 files changed

+344
-59
lines changed

11 files changed

+344
-59
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: b991bbe2d0f148d25d00a8c17bfa6304d1b1ae5a
2+
refs/heads/master: 629195582b39a4956cd62439911f0094cf3878c6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/libcollections/bitv.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,13 @@ impl Bitv {
486486
!self.none()
487487
}
488488

489-
pub fn init_to_vec(&self, i: uint) -> uint {
490-
return if self.get(i) { 1 } else { 0 };
491-
}
492-
493489
/**
494490
* Converts `self` to a vector of `uint` with the same length.
495491
*
496492
* Each `uint` in the resulting vector has either value `0u` or `1u`.
497493
*/
498494
pub fn to_vec(&self) -> Vec<uint> {
499-
Vec::from_fn(self.nbits, |x| self.init_to_vec(x))
495+
Vec::from_fn(self.nbits, |i| if self.get(i) { 1 } else { 0 })
500496
}
501497

502498
/**

trunk/src/libcore/iter.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ pub mod order {
21842184
use super::Iterator;
21852185

21862186
/// Compare `a` and `b` for equality using `TotalEq`
2187-
pub fn equals<A: TotalEq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2187+
pub fn equals<A: TotalEq, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
21882188
loop {
21892189
match (a.next(), b.next()) {
21902190
(None, None) => return true,
@@ -2195,7 +2195,7 @@ pub mod order {
21952195
}
21962196

21972197
/// Order `a` and `b` lexicographically using `TotalOrd`
2198-
pub fn cmp<A: TotalOrd, T: Iterator<A>>(mut a: T, mut b: T) -> cmp::Ordering {
2198+
pub fn cmp<A: TotalOrd, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> cmp::Ordering {
21992199
loop {
22002200
match (a.next(), b.next()) {
22012201
(None, None) => return cmp::Equal,
@@ -2210,7 +2210,7 @@ pub mod order {
22102210
}
22112211

22122212
/// Compare `a` and `b` for equality (Using partial equality, `Eq`)
2213-
pub fn eq<A: Eq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2213+
pub fn eq<A: Eq, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
22142214
loop {
22152215
match (a.next(), b.next()) {
22162216
(None, None) => return true,
@@ -2221,7 +2221,7 @@ pub mod order {
22212221
}
22222222

22232223
/// Compare `a` and `b` for nonequality (Using partial equality, `Eq`)
2224-
pub fn ne<A: Eq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2224+
pub fn ne<A: Eq, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
22252225
loop {
22262226
match (a.next(), b.next()) {
22272227
(None, None) => return false,
@@ -2232,7 +2232,7 @@ pub mod order {
22322232
}
22332233

22342234
/// Return `a` < `b` lexicographically (Using partial order, `Ord`)
2235-
pub fn lt<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2235+
pub fn lt<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
22362236
loop {
22372237
match (a.next(), b.next()) {
22382238
(None, None) => return false,
@@ -2244,7 +2244,7 @@ pub mod order {
22442244
}
22452245

22462246
/// Return `a` <= `b` lexicographically (Using partial order, `Ord`)
2247-
pub fn le<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2247+
pub fn le<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
22482248
loop {
22492249
match (a.next(), b.next()) {
22502250
(None, None) => return true,
@@ -2256,7 +2256,7 @@ pub mod order {
22562256
}
22572257

22582258
/// Return `a` > `b` lexicographically (Using partial order, `Ord`)
2259-
pub fn gt<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2259+
pub fn gt<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
22602260
loop {
22612261
match (a.next(), b.next()) {
22622262
(None, None) => return false,
@@ -2268,7 +2268,7 @@ pub mod order {
22682268
}
22692269

22702270
/// Return `a` >= `b` lexicographically (Using partial order, `Ord`)
2271-
pub fn ge<A: Ord, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
2271+
pub fn ge<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> bool {
22722272
loop {
22732273
match (a.next(), b.next()) {
22742274
(None, None) => return true,
@@ -2325,6 +2325,16 @@ pub mod order {
23252325
assert!(gt(c.iter(), b.iter()) == (c[0] > b[0]));
23262326
assert!(ge(c.iter(), b.iter()) == (c[0] >= b[0]));
23272327
}
2328+
2329+
#[test]
2330+
fn test_multi_iter() {
2331+
use slice::ImmutableVector;
2332+
use iter::DoubleEndedIterator;
2333+
let xs = [1i,2,3,4];
2334+
let ys = [4i,3,2,1];
2335+
assert!(eq(xs.iter(), ys.iter().rev()));
2336+
assert!(lt(xs.iter(), xs.iter().skip(2)));
2337+
}
23282338
}
23292339

23302340
#[cfg(test)]

trunk/src/libcore/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//!
1818
//! * `memcpy`, `memcmp`, `memset` - These are core memory routines which are
1919
//! often generated by LLVM. Additionally, this library can make explicit
20-
//! calls to these funcitons. Their signatures are the same as found in C.
20+
//! calls to these functions. Their signatures are the same as found in C.
2121
//! These functions are often provided by the system libc, but can also be
2222
//! provided by `librlibc` which is distributed with the standard rust
2323
//! distribution.

trunk/src/libcore/result.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,19 @@ impl<T, E> Result<T, E> {
508508
/// Unwraps a result, yielding the content of an `Ok`.
509509
/// If the value is an `Err` then it calls `op` with its value.
510510
#[inline]
511-
pub fn unwrap_or_handle(self, op: |E| -> T) -> T {
511+
pub fn unwrap_or_else(self, op: |E| -> T) -> T {
512512
match self {
513513
Ok(t) => t,
514514
Err(e) => op(e)
515515
}
516516
}
517+
518+
/// Deprecated name for `unwrap_or_else()`.
519+
#[deprecated = "replaced by .unwrap_or_else()"]
520+
#[inline]
521+
pub fn unwrap_or_handle(self, op: |E| -> T) -> T {
522+
self.unwrap_or_else(op)
523+
}
517524
}
518525

519526
impl<T, E: Show> Result<T, E> {
@@ -758,8 +765,8 @@ mod tests {
758765
let ok: Result<int, ~str> = Ok(100);
759766
let ok_err: Result<int, ~str> = Err("I got this.".to_owned());
760767

761-
assert_eq!(ok.unwrap_or_handle(handler), 100);
762-
assert_eq!(ok_err.unwrap_or_handle(handler), 50);
768+
assert_eq!(ok.unwrap_or_else(handler), 100);
769+
assert_eq!(ok_err.unwrap_or_else(handler), 50);
763770
}
764771

765772
#[test]
@@ -774,6 +781,6 @@ mod tests {
774781
}
775782

776783
let bad_err: Result<int, ~str> = Err("Unrecoverable mess.".to_owned());
777-
let _ : int = bad_err.unwrap_or_handle(handler);
784+
let _ : int = bad_err.unwrap_or_else(handler);
778785
}
779786
}

trunk/src/librustc/middle/resolve.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,6 +4891,25 @@ impl<'a> Resolver<'a> {
48914891
}
48924892

48934893
fn find_fallback_in_self_type(&mut self, name: Name) -> FallbackSuggestion {
4894+
#[deriving(Eq)]
4895+
enum FallbackChecks {
4896+
Everything,
4897+
OnlyTraitAndStatics
4898+
}
4899+
4900+
fn extract_path_and_node_id(t: &Ty, allow: FallbackChecks)
4901+
-> Option<(Path, NodeId, FallbackChecks)> {
4902+
match t.node {
4903+
TyPath(ref path, _, node_id) => Some((path.clone(), node_id, allow)),
4904+
TyPtr(mut_ty) => extract_path_and_node_id(mut_ty.ty, OnlyTraitAndStatics),
4905+
TyRptr(_, mut_ty) => extract_path_and_node_id(mut_ty.ty, allow),
4906+
// This doesn't handle the remaining `Ty` variants as they are not
4907+
// that commonly the self_type, it might be interesting to provide
4908+
// support for those in future.
4909+
_ => None,
4910+
}
4911+
}
4912+
48944913
fn get_module(this: &mut Resolver, span: Span, ident_path: &[ast::Ident])
48954914
-> Option<Rc<Module>> {
48964915
let root = this.current_module.clone();
@@ -4918,27 +4937,29 @@ impl<'a> Resolver<'a> {
49184937
}
49194938
}
49204939

4921-
let (path, node_id) = match self.current_self_type {
4922-
Some(ref ty) => match ty.node {
4923-
TyPath(ref path, _, node_id) => (path.clone(), node_id),
4924-
_ => unreachable!(),
4940+
let (path, node_id, allowed) = match self.current_self_type {
4941+
Some(ref ty) => match extract_path_and_node_id(ty, Everything) {
4942+
Some(x) => x,
4943+
None => return NoSuggestion,
49254944
},
49264945
None => return NoSuggestion,
49274946
};
49284947

4929-
// Look for a field with the same name in the current self_type.
4930-
match self.def_map.borrow().find(&node_id) {
4931-
Some(&DefTy(did))
4932-
| Some(&DefStruct(did))
4933-
| Some(&DefVariant(_, did, _)) => match self.structs.find(&did) {
4934-
None => {}
4935-
Some(fields) => {
4936-
if fields.iter().any(|&field_name| name == field_name) {
4937-
return Field;
4948+
if allowed == Everything {
4949+
// Look for a field with the same name in the current self_type.
4950+
match self.def_map.borrow().find(&node_id) {
4951+
Some(&DefTy(did))
4952+
| Some(&DefStruct(did))
4953+
| Some(&DefVariant(_, did, _)) => match self.structs.find(&did) {
4954+
None => {}
4955+
Some(fields) => {
4956+
if fields.iter().any(|&field_name| name == field_name) {
4957+
return Field;
4958+
}
49384959
}
4939-
}
4940-
},
4941-
_ => {} // Self type didn't resolve properly
4960+
},
4961+
_ => {} // Self type didn't resolve properly
4962+
}
49424963
}
49434964

49444965
let ident_path = path.segments.iter().map(|seg| seg.identifier).collect::<Vec<_>>();
@@ -4955,8 +4976,8 @@ impl<'a> Resolver<'a> {
49554976
FromTrait(_) => unreachable!()
49564977
}
49574978
}
4958-
Some(DefMethod(_, None)) => return Method,
4959-
Some(DefMethod(_, _)) => return TraitMethod,
4979+
Some(DefMethod(_, None)) if allowed == Everything => return Method,
4980+
Some(DefMethod(_, Some(_))) => return TraitMethod,
49604981
_ => ()
49614982
}
49624983
}

trunk/src/libtest/lib.rs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
3333
html_root_url = "http://static.rust-lang.org/doc/master")]
3434

35-
#![feature(asm, macro_rules)]
35+
#![feature(asm, macro_rules, phase)]
3636
#![deny(deprecated_owned_vector)]
3737

3838
extern crate collections;
@@ -83,7 +83,7 @@ pub mod stats;
8383
// colons. This way if some test runner wants to arrange the tests
8484
// hierarchically it may.
8585

86-
#[deriving(Clone)]
86+
#[deriving(Clone, Eq, TotalEq, Hash)]
8787
pub enum TestName {
8888
StaticTestName(&'static str),
8989
DynTestName(StrBuf)
@@ -156,6 +156,19 @@ impl TestFn {
156156
}
157157
}
158158

159+
impl fmt::Show for TestFn {
160+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161+
f.write(match *self {
162+
StaticTestFn(..) => "StaticTestFn(..)",
163+
StaticBenchFn(..) => "StaticBenchFn(..)",
164+
StaticMetricFn(..) => "StaticMetricFn(..)",
165+
DynTestFn(..) => "DynTestFn(..)",
166+
DynMetricFn(..) => "DynMetricFn(..)",
167+
DynBenchFn(..) => "DynBenchFn(..)"
168+
}.as_bytes())
169+
}
170+
}
171+
159172
/// Manager of the benchmarking runs.
160173
///
161174
/// This is feed into functions marked with `#[bench]` to allow for
@@ -170,13 +183,14 @@ pub struct Bencher {
170183

171184
// The definition of a single test. A test runner will run a list of
172185
// these.
173-
#[deriving(Clone)]
186+
#[deriving(Clone, Show, Eq, TotalEq, Hash)]
174187
pub struct TestDesc {
175188
pub name: TestName,
176189
pub ignore: bool,
177190
pub should_fail: bool,
178191
}
179192

193+
#[deriving(Show)]
180194
pub struct TestDescAndFn {
181195
pub desc: TestDesc,
182196
pub testfn: TestFn,
@@ -242,15 +256,9 @@ pub fn test_main(args: &[StrBuf], tests: Vec<TestDescAndFn> ) {
242256
pub fn test_main_static(args: &[StrBuf], tests: &[TestDescAndFn]) {
243257
let owned_tests = tests.iter().map(|t| {
244258
match t.testfn {
245-
StaticTestFn(f) =>
246-
TestDescAndFn { testfn: StaticTestFn(f), desc: t.desc.clone() },
247-
248-
StaticBenchFn(f) =>
249-
TestDescAndFn { testfn: StaticBenchFn(f), desc: t.desc.clone() },
250-
251-
_ => {
252-
fail!("non-static tests passed to test::test_main_static");
253-
}
259+
StaticTestFn(f) => TestDescAndFn { testfn: StaticTestFn(f), desc: t.desc.clone() },
260+
StaticBenchFn(f) => TestDescAndFn { testfn: StaticBenchFn(f), desc: t.desc.clone() },
261+
_ => fail!("non-static tests passed to test::test_main_static")
254262
}
255263
}).collect();
256264
test_main(args, owned_tests)
@@ -419,8 +427,15 @@ pub fn opt_shard(maybestr: Option<StrBuf>) -> Option<(uint,uint)> {
419427
None => None,
420428
Some(s) => {
421429
let mut it = s.as_slice().split('.');
422-
match (it.next().and_then(from_str), it.next().and_then(from_str), it.next()) {
423-
(Some(a), Some(b), None) => Some((a, b)),
430+
match (it.next().and_then(from_str::<uint>), it.next().and_then(from_str::<uint>),
431+
it.next()) {
432+
(Some(a), Some(b), None) => {
433+
if a <= 0 || a > b {
434+
fail!("tried to run shard {a}.{b}, but {a} is out of bounds \
435+
(should be between 1 and {b}", a=a, b=b)
436+
}
437+
Some((a, b))
438+
}
424439
_ => None,
425440
}
426441
}
@@ -739,10 +754,9 @@ pub fn fmt_bench_samples(bs: &BenchSamples) -> StrBuf {
739754
}
740755

741756
// A simple console test runner
742-
pub fn run_tests_console(opts: &TestOpts,
743-
tests: Vec<TestDescAndFn> ) -> io::IoResult<bool> {
744-
fn callback<T: Writer>(event: &TestEvent,
745-
st: &mut ConsoleTestState<T>) -> io::IoResult<()> {
757+
pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn> ) -> io::IoResult<bool> {
758+
759+
fn callback<T: Writer>(event: &TestEvent, st: &mut ConsoleTestState<T>) -> io::IoResult<()> {
746760
match (*event).clone() {
747761
TeFiltered(ref filtered_tests) => st.write_run_start(filtered_tests.len()),
748762
TeWait(ref test, padding) => st.write_test_start(test, padding),
@@ -778,6 +792,7 @@ pub fn run_tests_console(opts: &TestOpts,
778792
}
779793
}
780794
}
795+
781796
let mut st = try!(ConsoleTestState::new(opts, None::<StdWriter>));
782797
fn len_if_padded(t: &TestDescAndFn) -> uint {
783798
match t.testfn.padding() {
@@ -933,9 +948,7 @@ fn get_concurrency() -> uint {
933948
}
934949
}
935950

936-
pub fn filter_tests(
937-
opts: &TestOpts,
938-
tests: Vec<TestDescAndFn> ) -> Vec<TestDescAndFn> {
951+
pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescAndFn> {
939952
let mut filtered = tests;
940953

941954
// Remove tests that don't match the test filter
@@ -973,7 +986,9 @@ pub fn filter_tests(
973986
None => filtered,
974987
Some((a,b)) => {
975988
filtered.move_iter().enumerate()
976-
.filter(|&(i,_)| i % b == a)
989+
// note: using a - 1 so that the valid shards, for example, are
990+
// 1.2 and 2.2 instead of 0.2 and 1.2
991+
.filter(|&(i,_)| i % b == (a - 1))
977992
.map(|(_,t)| t)
978993
.collect()
979994
}

0 commit comments

Comments
 (0)