Skip to content

Port a half dozen passes or so to the new visitor #8567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ mod tests {

#[test]
fn test_basic() {
let mut m = DList::new::<~int>();
let mut m: DList<~int> = DList::new();
assert_eq!(m.pop_front(), None);
assert_eq!(m.pop_back(), None);
assert_eq!(m.pop_front(), None);
Expand Down Expand Up @@ -768,7 +768,7 @@ mod tests {

#[test]
fn test_rotate() {
let mut n = DList::new::<int>();
let mut n: DList<int> = DList::new();
n.rotate_backward(); check_links(&n);
assert_eq!(n.len(), 0);
n.rotate_forward(); check_links(&n);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ mod tests {

#[cfg(test)]
fn fuzz_test(sz: int) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
let mut v = ~[];
for i in range(0, sz) {
check_links(&m);
Expand Down Expand Up @@ -1078,23 +1078,23 @@ mod tests {

#[bench]
fn bench_push_front(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_front(0);
}
}

#[bench]
fn bench_push_back(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_back(0);
}
}

#[bench]
fn bench_push_back_pop_back(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_back(0);
m.pop_back();
Expand All @@ -1103,7 +1103,7 @@ mod tests {

#[bench]
fn bench_push_front_pop_front(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
do b.iter {
m.push_front(0);
m.pop_front();
Expand All @@ -1112,7 +1112,7 @@ mod tests {

#[bench]
fn bench_rotate_forward(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
m.push_front(0);
m.push_front(1);
do b.iter {
Expand All @@ -1122,7 +1122,7 @@ mod tests {

#[bench]
fn bench_rotate_backward(b: &mut test::BenchHarness) {
let mut m = DList::new::<int>();
let mut m: DList<int> = DList::new();
m.push_front(0);
m.push_front(1);
do b.iter {
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub mod rustrt {

#[link_name = "rustrt"]
extern {
pub fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *c_void;

pub fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
Expand Down
61 changes: 42 additions & 19 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl Integer for BigUint {

fn div_mod_floor_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
let mut m = a;
let mut d = Zero::zero::<BigUint>();
let mut d: BigUint = Zero::zero();
let mut n = 1;
while m >= b {
let (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
Expand Down Expand Up @@ -432,8 +432,9 @@ impl Integer for BigUint {
if shift == 0 {
return (BigUint::new(d), One::one(), (*b).clone());
}
let one: BigUint = One::one();
return (BigUint::from_slice(d).shl_unit(shift),
One::one::<BigUint>().shl_unit(shift),
one.shl_unit(shift),
b.shl_unit(shift));
}
}
Expand Down Expand Up @@ -1510,11 +1511,18 @@ mod biguint_tests {

#[test]
fn test_is_even() {
assert!(FromStr::from_str::<BigUint>("1").unwrap().is_odd());
assert!(FromStr::from_str::<BigUint>("2").unwrap().is_even());
assert!(FromStr::from_str::<BigUint>("1000").unwrap().is_even());
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").unwrap().is_even());
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").unwrap().is_odd());
let one: Option<BigUint> = FromStr::from_str("1");
let two: Option<BigUint> = FromStr::from_str("2");
let thousand: Option<BigUint> = FromStr::from_str("1000");
let big: Option<BigUint> =
FromStr::from_str("1000000000000000000000");
let bigger: Option<BigUint> =
FromStr::from_str("1000000000000000000001");
assert!(one.unwrap().is_odd());
assert!(two.unwrap().is_even());
assert!(thousand.unwrap().is_even());
assert!(big.unwrap().is_even());
assert!(bigger.unwrap().is_odd());
assert!((BigUint::from_uint(1) << 64).is_even());
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
}
Expand Down Expand Up @@ -1599,15 +1607,19 @@ mod biguint_tests {
}
}

assert_eq!(FromStrRadix::from_str_radix::<BigUint>("Z", 10), None);
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("_", 2), None);
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("-1", 10), None);
let zed: Option<BigUint> = FromStrRadix::from_str_radix("Z", 10);
assert_eq!(zed, None);
let blank: Option<BigUint> = FromStrRadix::from_str_radix("_", 2);
assert_eq!(blank, None);
let minus_one: Option<BigUint> = FromStrRadix::from_str_radix("-1",
10);
assert_eq!(minus_one, None);
}

#[test]
fn test_factor() {
fn factor(n: uint) -> BigUint {
let mut f= One::one::<BigUint>();
let mut f: BigUint = One::one();
for i in range(2, n + 1) {
// FIXME(#6102): Assignment operator for BigInt causes ICE
// f *= BigUint::from_uint(i);
Expand Down Expand Up @@ -2005,17 +2017,24 @@ mod bigint_tests {

#[test]
fn test_abs_sub() {
assert_eq!((-One::one::<BigInt>()).abs_sub(&One::one()), Zero::zero());
assert_eq!(One::one::<BigInt>().abs_sub(&One::one()), Zero::zero());
assert_eq!(One::one::<BigInt>().abs_sub(&Zero::zero()), One::one());
assert_eq!(One::one::<BigInt>().abs_sub(&-One::one::<BigInt>()),
IntConvertible::from_int(2));
let zero: BigInt = Zero::zero();
let one: BigInt = One::one();
assert_eq!((-one).abs_sub(&one), zero);
let one: BigInt = One::one();
let zero: BigInt = Zero::zero();
assert_eq!(one.abs_sub(&one), zero);
let one: BigInt = One::one();
let zero: BigInt = Zero::zero();
assert_eq!(one.abs_sub(&zero), one);
let one: BigInt = One::one();
assert_eq!(one.abs_sub(&-one), IntConvertible::from_int(2));
}

#[test]
fn test_to_str_radix() {
fn check(n: int, ans: &str) {
assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10));
let n: BigInt = IntConvertible::from_int(n);
assert!(ans == n.to_str_radix(10));
}
check(10, "10");
check(1, "1");
Expand All @@ -2028,7 +2047,10 @@ mod bigint_tests {
#[test]
fn test_from_str_radix() {
fn check(s: &str, ans: Option<int>) {
let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
let ans = ans.map_move(|n| {
let x: BigInt = IntConvertible::from_int(n);
x
});
assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
}
check("10", Some(10));
Expand All @@ -2046,6 +2068,7 @@ mod bigint_tests {
BigInt::new(Minus, ~[1, 1, 1]));
assert!(-BigInt::new(Minus, ~[1, 1, 1]) ==
BigInt::new(Plus, ~[1, 1, 1]));
assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>());
let zero: BigInt = Zero::zero();
assert_eq!(-zero, zero);
}
}
29 changes: 20 additions & 9 deletions src/libextra/num/rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,13 @@ impl<T: FromStr + Clone + Integer + Ord>
/// Parses `numer/denom`.
fn from_str(s: &str) -> Option<Ratio<T>> {
let split: ~[&str] = s.splitn_iter('/', 1).collect();
if split.len() < 2 { return None; }
do FromStr::from_str::<T>(split[0]).chain |a| {
do FromStr::from_str::<T>(split[1]).chain |b| {
if split.len() < 2 {
return None
}
let a_option: Option<T> = FromStr::from_str(split[0]);
do a_option.chain |a| {
let b_option: Option<T> = FromStr::from_str(split[1]);
do b_option.chain |b| {
Some(Ratio::new(a.clone(), b.clone()))
}
}
Expand All @@ -282,10 +286,15 @@ impl<T: FromStrRadix + Clone + Integer + Ord>
/// Parses `numer/denom` where the numbers are in base `radix`.
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
let split: ~[&str] = s.splitn_iter('/', 1).collect();
if split.len() < 2 { None }
else {
do FromStrRadix::from_str_radix::<T>(split[0], radix).chain |a| {
do FromStrRadix::from_str_radix::<T>(split[1], radix).chain |b| {
if split.len() < 2 {
None
} else {
let a_option: Option<T> = FromStrRadix::from_str_radix(split[0],
radix);
do a_option.chain |a| {
let b_option: Option<T> =
FromStrRadix::from_str_radix(split[1], radix);
do b_option.chain |b| {
Some(Ratio::new(a.clone(), b.clone()))
}
}
Expand Down Expand Up @@ -496,7 +505,8 @@ mod test {
#[test]
fn test_from_str_fail() {
fn test(s: &str) {
assert_eq!(FromStr::from_str::<Rational>(s), None);
let rational: Option<Rational> = FromStr::from_str(s);
assert_eq!(rational, None);
}

let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1"];
Expand Down Expand Up @@ -536,7 +546,8 @@ mod test {
#[test]
fn test_from_str_radix_fail() {
fn test(s: &str) {
assert_eq!(FromStrRadix::from_str_radix::<Rational>(s, 3), None);
let radix: Option<Rational> = FromStrRadix::from_str_radix(s, 3);
assert_eq!(radix, None);
}

let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1", "3/2"];
Expand Down
19 changes: 14 additions & 5 deletions src/libextra/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,29 +339,38 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_empty_pop() { let mut heap = PriorityQueue::new::<int>(); heap.pop(); }
fn test_empty_pop() {
let mut heap: PriorityQueue<int> = PriorityQueue::new();
heap.pop();
}

#[test]
fn test_empty_maybe_pop() {
let mut heap = PriorityQueue::new::<int>();
let mut heap: PriorityQueue<int> = PriorityQueue::new();
assert!(heap.maybe_pop().is_none());
}

#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_empty_top() { let empty = PriorityQueue::new::<int>(); empty.top(); }
fn test_empty_top() {
let empty: PriorityQueue<int> = PriorityQueue::new();
empty.top();
}

#[test]
fn test_empty_maybe_top() {
let empty = PriorityQueue::new::<int>();
let empty: PriorityQueue<int> = PriorityQueue::new();
assert!(empty.maybe_top().is_none());
}

#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_empty_replace() { let mut heap = PriorityQueue::new(); heap.replace(5); }
fn test_empty_replace() {
let mut heap: PriorityQueue<int> = PriorityQueue::new();
heap.replace(5);
}

#[test]
fn test_from_iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ mod tests {
#[bench]
fn bench_new(b: &mut test::BenchHarness) {
do b.iter {
let _ = RingBuf::new::<u64>();
let _: RingBuf<u64> = RingBuf::new();
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ mod test_treemap {

#[test]
fn find_empty() {
let m = TreeMap::new::<int, int>(); assert!(m.find(&5) == None);
let m: TreeMap<int,int> = TreeMap::new();
assert!(m.find(&5) == None);
}

#[test]
Expand Down Expand Up @@ -1006,7 +1007,7 @@ mod test_treemap {

#[test]
fn test_rand_int() {
let mut map = TreeMap::new::<int, int>();
let mut map: TreeMap<int,int> = TreeMap::new();
let mut ctrl = ~[];

check_equal(ctrl, &map);
Expand Down
17 changes: 12 additions & 5 deletions src/librustc/front/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use syntax::attr;
use syntax::codemap::dummy_sp;
use syntax::codemap;
use syntax::fold;
use syntax::opt_vec;

static STD_VERSION: &'static str = "0.8-pre";

Expand Down Expand Up @@ -90,12 +91,18 @@ fn inject_libstd_ref(sess: Session, crate: &ast::Crate) -> @ast::Crate {
let prelude_path = ast::Path {
span: dummy_sp(),
global: false,
idents: ~[
sess.ident_of("std"),
sess.ident_of("prelude")
segments: ~[
ast::PathSegment {
identifier: sess.ident_of("std"),
lifetime: None,
types: opt_vec::Empty,
},
ast::PathSegment {
identifier: sess.ident_of("prelude"),
lifetime: None,
types: opt_vec::Empty,
},
],
rp: None,
types: ~[]
};

let vp = @spanned(ast::view_path_glob(prelude_path, n2));
Expand Down
Loading