Skip to content

Commit 578e680

Browse files
committed
auto merge of #8802 : pcwalton/rust/compile-speed, r=brson
r? @brson
2 parents 3211713 + aac9d6e commit 578e680

File tree

143 files changed

+3067
-1780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+3067
-1780
lines changed

doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ Some examples of call expressions:
22302230
# fn add(x: int, y: int) -> int { 0 }
22312231
22322232
let x: int = add(1, 2);
2233-
let pi = FromStr::from_str::<f32>("3.14");
2233+
let pi: Option<f32> = FromStr::from_str("3.14");
22342234
~~~~
22352235

22362236
### Lambda expressions

src/libextra/crypto/cryptoutil.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ mod test {
420420
#[test]
421421
#[should_fail]
422422
fn test_add_bytes_to_bits_tuple_overflow2() {
423-
add_bytes_to_bits_tuple::<u64>((Bounded::max_value::<u64>() - 1, 0), 0x8000000000000000);
423+
let value: u64 = Bounded::max_value();
424+
add_bytes_to_bits_tuple::<u64>((value - 1, 0), 0x8000000000000000);
424425
}
425426
}

src/libextra/dlist.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ mod tests {
661661

662662
#[test]
663663
fn test_basic() {
664-
let mut m = DList::new::<~int>();
664+
let mut m: DList<~int> = DList::new();
665665
assert_eq!(m.pop_front(), None);
666666
assert_eq!(m.pop_back(), None);
667667
assert_eq!(m.pop_front(), None);
@@ -768,7 +768,7 @@ mod tests {
768768

769769
#[test]
770770
fn test_rotate() {
771-
let mut n = DList::new::<int>();
771+
let mut n: DList<int> = DList::new();
772772
n.rotate_backward(); check_links(&n);
773773
assert_eq!(n.len(), 0);
774774
n.rotate_forward(); check_links(&n);
@@ -1033,7 +1033,7 @@ mod tests {
10331033

10341034
#[cfg(test)]
10351035
fn fuzz_test(sz: int) {
1036-
let mut m = DList::new::<int>();
1036+
let mut m: DList<int> = DList::new();
10371037
let mut v = ~[];
10381038
for i in range(0, sz) {
10391039
check_links(&m);
@@ -1078,23 +1078,23 @@ mod tests {
10781078

10791079
#[bench]
10801080
fn bench_push_front(b: &mut test::BenchHarness) {
1081-
let mut m = DList::new::<int>();
1081+
let mut m: DList<int> = DList::new();
10821082
do b.iter {
10831083
m.push_front(0);
10841084
}
10851085
}
10861086

10871087
#[bench]
10881088
fn bench_push_back(b: &mut test::BenchHarness) {
1089-
let mut m = DList::new::<int>();
1089+
let mut m: DList<int> = DList::new();
10901090
do b.iter {
10911091
m.push_back(0);
10921092
}
10931093
}
10941094

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

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

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

11231123
#[bench]
11241124
fn bench_rotate_backward(b: &mut test::BenchHarness) {
1125-
let mut m = DList::new::<int>();
1125+
let mut m: DList<int> = DList::new();
11261126
m.push_front(0);
11271127
m.push_front(1);
11281128
do b.iter {

src/libextra/flate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub mod rustrt {
2525

2626
#[link_name = "rustrt"]
2727
extern {
28-
pub fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
28+
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,
2929
src_buf_len: size_t,
3030
pout_len: *mut size_t,
3131
flags: c_int)
3232
-> *c_void;
3333

34-
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
34+
pub fn tinfl_decompress_mem_to_heap(psrc_buf: *c_void,
3535
src_buf_len: size_t,
3636
pout_len: *mut size_t,
3737
flags: c_int)

src/libextra/num/bigint.rs

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl Integer for BigUint {
359359

360360
fn div_mod_floor_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
361361
let mut m = a;
362-
let mut d = Zero::zero::<BigUint>();
362+
let mut d: BigUint = Zero::zero();
363363
let mut n = 1;
364364
while m >= b {
365365
let (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
@@ -411,8 +411,9 @@ impl Integer for BigUint {
411411
if shift == 0 {
412412
return (BigUint::new(d), One::one(), (*b).clone());
413413
}
414+
let one: BigUint = One::one();
414415
return (BigUint::from_slice(d).shl_unit(shift),
415-
One::one::<BigUint>().shl_unit(shift),
416+
one.shl_unit(shift),
416417
b.shl_unit(shift));
417418
}
418419
}
@@ -1168,8 +1169,8 @@ mod biguint_tests {
11681169
#[test]
11691170
fn test_shl() {
11701171
fn check(s: &str, shift: uint, ans: &str) {
1171-
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() << shift)
1172-
.to_str_radix(16);
1172+
let opt_biguint: Option<BigUint> = FromStrRadix::from_str_radix(s, 16);
1173+
let bu = (opt_biguint.unwrap() << shift).to_str_radix(16);
11731174
assert_eq!(bu.as_slice(), ans);
11741175
}
11751176
@@ -1206,8 +1207,9 @@ mod biguint_tests {
12061207
#[test]
12071208
fn test_shr() {
12081209
fn check(s: &str, shift: uint, ans: &str) {
1209-
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() >> shift)
1210-
.to_str_radix(16);
1210+
let opt_biguint: Option<BigUint> =
1211+
FromStrRadix::from_str_radix(s, 16);
1212+
let bu = (opt_biguint.unwrap() >> shift).to_str_radix(16);
12111213
assert_eq!(bu.as_slice(), ans);
12121214
}
12131215

@@ -1445,11 +1447,18 @@ mod biguint_tests {
14451447

14461448
#[test]
14471449
fn test_is_even() {
1448-
assert!(FromStr::from_str::<BigUint>("1").unwrap().is_odd());
1449-
assert!(FromStr::from_str::<BigUint>("2").unwrap().is_even());
1450-
assert!(FromStr::from_str::<BigUint>("1000").unwrap().is_even());
1451-
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").unwrap().is_even());
1452-
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").unwrap().is_odd());
1450+
let one: Option<BigUint> = FromStr::from_str("1");
1451+
let two: Option<BigUint> = FromStr::from_str("2");
1452+
let thousand: Option<BigUint> = FromStr::from_str("1000");
1453+
let big: Option<BigUint> =
1454+
FromStr::from_str("1000000000000000000000");
1455+
let bigger: Option<BigUint> =
1456+
FromStr::from_str("1000000000000000000001");
1457+
assert!(one.unwrap().is_odd());
1458+
assert!(two.unwrap().is_even());
1459+
assert!(thousand.unwrap().is_even());
1460+
assert!(big.unwrap().is_even());
1461+
assert!(bigger.unwrap().is_odd());
14531462
assert!((BigUint::from_uint(1) << 64).is_even());
14541463
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
14551464
}
@@ -1534,15 +1543,19 @@ mod biguint_tests {
15341543
}
15351544
}
15361545

1537-
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("Z", 10), None);
1538-
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("_", 2), None);
1539-
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("-1", 10), None);
1546+
let zed: Option<BigUint> = FromStrRadix::from_str_radix("Z", 10);
1547+
assert_eq!(zed, None);
1548+
let blank: Option<BigUint> = FromStrRadix::from_str_radix("_", 2);
1549+
assert_eq!(blank, None);
1550+
let minus_one: Option<BigUint> = FromStrRadix::from_str_radix("-1",
1551+
10);
1552+
assert_eq!(minus_one, None);
15401553
}
15411554

15421555
#[test]
15431556
fn test_factor() {
15441557
fn factor(n: uint) -> BigUint {
1545-
let mut f= One::one::<BigUint>();
1558+
let mut f: BigUint = One::one();
15461559
for i in range(2, n + 1) {
15471560
// FIXME(#6102): Assignment operator for BigInt causes ICE
15481561
// f *= BigUint::from_uint(i);
@@ -1939,17 +1952,24 @@ mod bigint_tests {
19391952

19401953
#[test]
19411954
fn test_abs_sub() {
1942-
assert_eq!((-One::one::<BigInt>()).abs_sub(&One::one()), Zero::zero());
1943-
assert_eq!(One::one::<BigInt>().abs_sub(&One::one()), Zero::zero());
1944-
assert_eq!(One::one::<BigInt>().abs_sub(&Zero::zero()), One::one());
1945-
assert_eq!(One::one::<BigInt>().abs_sub(&-One::one::<BigInt>()),
1946-
IntConvertible::from_int(2));
1955+
let zero: BigInt = Zero::zero();
1956+
let one: BigInt = One::one();
1957+
assert_eq!((-one).abs_sub(&one), zero);
1958+
let one: BigInt = One::one();
1959+
let zero: BigInt = Zero::zero();
1960+
assert_eq!(one.abs_sub(&one), zero);
1961+
let one: BigInt = One::one();
1962+
let zero: BigInt = Zero::zero();
1963+
assert_eq!(one.abs_sub(&zero), one);
1964+
let one: BigInt = One::one();
1965+
assert_eq!(one.abs_sub(&-one), IntConvertible::from_int(2));
19471966
}
19481967

19491968
#[test]
19501969
fn test_to_str_radix() {
19511970
fn check(n: int, ans: &str) {
1952-
assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10));
1971+
let n: BigInt = IntConvertible::from_int(n);
1972+
assert!(ans == n.to_str_radix(10));
19531973
}
19541974
check(10, "10");
19551975
check(1, "1");
@@ -1962,7 +1982,10 @@ mod bigint_tests {
19621982
#[test]
19631983
fn test_from_str_radix() {
19641984
fn check(s: &str, ans: Option<int>) {
1965-
let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
1985+
let ans = ans.map_move(|n| {
1986+
let x: BigInt = IntConvertible::from_int(n);
1987+
x
1988+
});
19661989
assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
19671990
}
19681991
check("10", Some(10));
@@ -1980,7 +2003,8 @@ mod bigint_tests {
19802003
BigInt::new(Minus, ~[1, 1, 1]));
19812004
assert!(-BigInt::new(Minus, ~[1, 1, 1]) ==
19822005
BigInt::new(Plus, ~[1, 1, 1]));
1983-
assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>());
2006+
let zero: BigInt = Zero::zero();
2007+
assert_eq!(-zero, zero);
19842008
}
19852009
}
19862010

@@ -1992,16 +2016,16 @@ mod bench {
19922016
use extra::test::BenchHarness;
19932017

19942018
fn factorial(n: uint) -> BigUint {
1995-
let mut f = One::one::<BigUint>();
2019+
let mut f: BigUint = One::one();
19962020
for i in iterator::range_inclusive(1, n) {
19972021
f = f * BigUint::from_uint(i);
19982022
}
19992023
f
20002024
}
20012025

20022026
fn fib(n: uint) -> BigUint {
2003-
let mut f0 = Zero::zero::<BigUint>();
2004-
let mut f1 = One::one::<BigUint>();
2027+
let mut f0: BigUint = Zero::zero();
2028+
let mut f1: BigUint = One::one();
20052029
for _ in range(0, n) {
20062030
let f2 = f0 + f1;
20072031
f0 = util::replace(&mut f1, f2);

src/libextra/num/rational.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,13 @@ impl<T: FromStr + Clone + Integer + Ord>
269269
/// Parses `numer/denom`.
270270
fn from_str(s: &str) -> Option<Ratio<T>> {
271271
let split: ~[&str] = s.splitn_iter('/', 1).collect();
272-
if split.len() < 2 { return None; }
273-
do FromStr::from_str::<T>(split[0]).chain |a| {
274-
do FromStr::from_str::<T>(split[1]).chain |b| {
272+
if split.len() < 2 {
273+
return None
274+
}
275+
let a_option: Option<T> = FromStr::from_str(split[0]);
276+
do a_option.chain |a| {
277+
let b_option: Option<T> = FromStr::from_str(split[1]);
278+
do b_option.chain |b| {
275279
Some(Ratio::new(a.clone(), b.clone()))
276280
}
277281
}
@@ -282,10 +286,15 @@ impl<T: FromStrRadix + Clone + Integer + Ord>
282286
/// Parses `numer/denom` where the numbers are in base `radix`.
283287
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
284288
let split: ~[&str] = s.splitn_iter('/', 1).collect();
285-
if split.len() < 2 { None }
286-
else {
287-
do FromStrRadix::from_str_radix::<T>(split[0], radix).chain |a| {
288-
do FromStrRadix::from_str_radix::<T>(split[1], radix).chain |b| {
289+
if split.len() < 2 {
290+
None
291+
} else {
292+
let a_option: Option<T> = FromStrRadix::from_str_radix(split[0],
293+
radix);
294+
do a_option.chain |a| {
295+
let b_option: Option<T> =
296+
FromStrRadix::from_str_radix(split[1], radix);
297+
do b_option.chain |b| {
289298
Some(Ratio::new(a.clone(), b.clone()))
290299
}
291300
}
@@ -496,7 +505,8 @@ mod test {
496505
#[test]
497506
fn test_from_str_fail() {
498507
fn test(s: &str) {
499-
assert_eq!(FromStr::from_str::<Rational>(s), None);
508+
let rational: Option<Rational> = FromStr::from_str(s);
509+
assert_eq!(rational, None);
500510
}
501511

502512
let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1"];
@@ -536,7 +546,8 @@ mod test {
536546
#[test]
537547
fn test_from_str_radix_fail() {
538548
fn test(s: &str) {
539-
assert_eq!(FromStrRadix::from_str_radix::<Rational>(s, 3), None);
549+
let radix: Option<Rational> = FromStrRadix::from_str_radix(s, 3);
550+
assert_eq!(radix, None);
540551
}
541552

542553
let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1", "3/2"];

src/libextra/priority_queue.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,27 +338,36 @@ mod tests {
338338

339339
#[test]
340340
#[should_fail]
341-
fn test_empty_pop() { let mut heap = PriorityQueue::new::<int>(); heap.pop(); }
341+
fn test_empty_pop() {
342+
let mut heap: PriorityQueue<int> = PriorityQueue::new();
343+
heap.pop();
344+
}
342345

343346
#[test]
344347
fn test_empty_maybe_pop() {
345-
let mut heap = PriorityQueue::new::<int>();
348+
let mut heap: PriorityQueue<int> = PriorityQueue::new();
346349
assert!(heap.maybe_pop().is_none());
347350
}
348351

349352
#[test]
350353
#[should_fail]
351-
fn test_empty_top() { let empty = PriorityQueue::new::<int>(); empty.top(); }
354+
fn test_empty_top() {
355+
let empty: PriorityQueue<int> = PriorityQueue::new();
356+
empty.top();
357+
}
352358

353359
#[test]
354360
fn test_empty_maybe_top() {
355-
let empty = PriorityQueue::new::<int>();
361+
let empty: PriorityQueue<int> = PriorityQueue::new();
356362
assert!(empty.maybe_top().is_none());
357363
}
358364

359365
#[test]
360366
#[should_fail]
361-
fn test_empty_replace() { let mut heap = PriorityQueue::new(); heap.replace(5); }
367+
fn test_empty_replace() {
368+
let mut heap: PriorityQueue<int> = PriorityQueue::new();
369+
heap.replace(5);
370+
}
362371

363372
#[test]
364373
fn test_from_iter() {

src/libextra/ringbuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ mod tests {
483483
#[bench]
484484
fn bench_new(b: &mut test::BenchHarness) {
485485
do b.iter {
486-
let _ = RingBuf::new::<u64>();
486+
let _: RingBuf<u64> = RingBuf::new();
487487
}
488488
}
489489

src/libextra/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub fn write_boxplot(w: @io::Writer, s: &Summary, width_hint: uint) {
368368
/// Returns a HashMap with the number of occurrences of every element in the
369369
/// sequence that the iterator exposes.
370370
pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap<U, uint> {
371-
let mut map = hashmap::HashMap::new::<U, uint>();
371+
let mut map: hashmap::HashMap<U,uint> = hashmap::HashMap::new();
372372
for elem in iter {
373373
map.insert_or_update_with(elem, 1, |_, count| *count += 1);
374374
}

0 commit comments

Comments
 (0)