Skip to content

Commit fe37d81

Browse files
committed
librustc: Ensure that type parameters are in the right positions in paths.
This removes the stacking of type parameters that occurs when invoking trait methods, and fixes all places in the standard library that were relying on it. It is somewhat awkward in places; I think we'll probably want something like the `Foo::<for T>::new()` syntax.
1 parent f29c1f8 commit fe37d81

Some content is hidden

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

72 files changed

+1143
-544
lines changed

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/num/bigint.rs

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl Integer for BigUint {
380380

381381
fn div_mod_floor_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) {
382382
let mut m = a;
383-
let mut d = Zero::zero::<BigUint>();
383+
let mut d: BigUint = Zero::zero();
384384
let mut n = 1;
385385
while m >= b {
386386
let (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
@@ -432,8 +432,9 @@ impl Integer for BigUint {
432432
if shift == 0 {
433433
return (BigUint::new(d), One::one(), (*b).clone());
434434
}
435+
let one: BigUint = One::one();
435436
return (BigUint::from_slice(d).shl_unit(shift),
436-
One::one::<BigUint>().shl_unit(shift),
437+
one.shl_unit(shift),
437438
b.shl_unit(shift));
438439
}
439440
}
@@ -1510,11 +1511,18 @@ mod biguint_tests {
15101511

15111512
#[test]
15121513
fn test_is_even() {
1513-
assert!(FromStr::from_str::<BigUint>("1").unwrap().is_odd());
1514-
assert!(FromStr::from_str::<BigUint>("2").unwrap().is_even());
1515-
assert!(FromStr::from_str::<BigUint>("1000").unwrap().is_even());
1516-
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").unwrap().is_even());
1517-
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").unwrap().is_odd());
1514+
let one: Option<BigUint> = FromStr::from_str("1");
1515+
let two: Option<BigUint> = FromStr::from_str("2");
1516+
let thousand: Option<BigUint> = FromStr::from_str("1000");
1517+
let big: Option<BigUint> =
1518+
FromStr::from_str("1000000000000000000000");
1519+
let bigger: Option<BigUint> =
1520+
FromStr::from_str("1000000000000000000001");
1521+
assert!(one.unwrap().is_odd());
1522+
assert!(two.unwrap().is_even());
1523+
assert!(thousand.unwrap().is_even());
1524+
assert!(big.unwrap().is_even());
1525+
assert!(bigger.unwrap().is_odd());
15181526
assert!((BigUint::from_uint(1) << 64).is_even());
15191527
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
15201528
}
@@ -1599,15 +1607,19 @@ mod biguint_tests {
15991607
}
16001608
}
16011609

1602-
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("Z", 10), None);
1603-
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("_", 2), None);
1604-
assert_eq!(FromStrRadix::from_str_radix::<BigUint>("-1", 10), None);
1610+
let zed: Option<BigUint> = FromStrRadix::from_str_radix("Z", 10);
1611+
assert_eq!(zed, None);
1612+
let blank: Option<BigUint> = FromStrRadix::from_str_radix("_", 2);
1613+
assert_eq!(blank, None);
1614+
let minus_one: Option<BigUint> = FromStrRadix::from_str_radix("-1",
1615+
10);
1616+
assert_eq!(minus_one, None);
16051617
}
16061618

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

20062018
#[test]
20072019
fn test_abs_sub() {
2008-
assert_eq!((-One::one::<BigInt>()).abs_sub(&One::one()), Zero::zero());
2009-
assert_eq!(One::one::<BigInt>().abs_sub(&One::one()), Zero::zero());
2010-
assert_eq!(One::one::<BigInt>().abs_sub(&Zero::zero()), One::one());
2011-
assert_eq!(One::one::<BigInt>().abs_sub(&-One::one::<BigInt>()),
2012-
IntConvertible::from_int(2));
2020+
let zero: BigInt = Zero::zero();
2021+
let one: BigInt = One::one();
2022+
assert_eq!((-one).abs_sub(&one), zero);
2023+
let one: BigInt = One::one();
2024+
let zero: BigInt = Zero::zero();
2025+
assert_eq!(one.abs_sub(&one), zero);
2026+
let one: BigInt = One::one();
2027+
let zero: BigInt = Zero::zero();
2028+
assert_eq!(one.abs_sub(&zero), one);
2029+
let one: BigInt = One::one();
2030+
assert_eq!(one.abs_sub(&-one), IntConvertible::from_int(2));
20132031
}
20142032

20152033
#[test]
20162034
fn test_to_str_radix() {
20172035
fn check(n: int, ans: &str) {
2018-
assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10));
2036+
let n: BigInt = IntConvertible::from_int(n);
2037+
assert!(ans == n.to_str_radix(10));
20192038
}
20202039
check(10, "10");
20212040
check(1, "1");
@@ -2028,7 +2047,10 @@ mod bigint_tests {
20282047
#[test]
20292048
fn test_from_str_radix() {
20302049
fn check(s: &str, ans: Option<int>) {
2031-
let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
2050+
let ans = ans.map_move(|n| {
2051+
let x: BigInt = IntConvertible::from_int(n);
2052+
x
2053+
});
20322054
assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
20332055
}
20342056
check("10", Some(10));
@@ -2046,6 +2068,7 @@ mod bigint_tests {
20462068
BigInt::new(Minus, ~[1, 1, 1]));
20472069
assert!(-BigInt::new(Minus, ~[1, 1, 1]) ==
20482070
BigInt::new(Plus, ~[1, 1, 1]));
2049-
assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>());
2071+
let zero: BigInt = Zero::zero();
2072+
assert_eq!(-zero, zero);
20502073
}
20512074
}

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
@@ -339,29 +339,38 @@ mod tests {
339339
#[test]
340340
#[should_fail]
341341
#[ignore(cfg(windows))]
342-
fn test_empty_pop() { let mut heap = PriorityQueue::new::<int>(); heap.pop(); }
342+
fn test_empty_pop() {
343+
let mut heap: PriorityQueue<int> = PriorityQueue::new();
344+
heap.pop();
345+
}
343346

344347
#[test]
345348
fn test_empty_maybe_pop() {
346-
let mut heap = PriorityQueue::new::<int>();
349+
let mut heap: PriorityQueue<int> = PriorityQueue::new();
347350
assert!(heap.maybe_pop().is_none());
348351
}
349352

350353
#[test]
351354
#[should_fail]
352355
#[ignore(cfg(windows))]
353-
fn test_empty_top() { let empty = PriorityQueue::new::<int>(); empty.top(); }
356+
fn test_empty_top() {
357+
let empty: PriorityQueue<int> = PriorityQueue::new();
358+
empty.top();
359+
}
354360

355361
#[test]
356362
fn test_empty_maybe_top() {
357-
let empty = PriorityQueue::new::<int>();
363+
let empty: PriorityQueue<int> = PriorityQueue::new();
358364
assert!(empty.maybe_top().is_none());
359365
}
360366

361367
#[test]
362368
#[should_fail]
363369
#[ignore(cfg(windows))]
364-
fn test_empty_replace() { let mut heap = PriorityQueue::new(); heap.replace(5); }
370+
fn test_empty_replace() {
371+
let mut heap: PriorityQueue<int> = PriorityQueue::new();
372+
heap.replace(5);
373+
}
365374

366375
#[test]
367376
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/treemap.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ mod test_treemap {
879879

880880
#[test]
881881
fn find_empty() {
882-
let m = TreeMap::new::<int, int>(); assert!(m.find(&5) == None);
882+
let m: TreeMap<int,int> = TreeMap::new();
883+
assert!(m.find(&5) == None);
883884
}
884885

885886
#[test]
@@ -1006,7 +1007,7 @@ mod test_treemap {
10061007

10071008
#[test]
10081009
fn test_rand_int() {
1009-
let mut map = TreeMap::new::<int, int>();
1010+
let mut map: TreeMap<int,int> = TreeMap::new();
10101011
let mut ctrl = ~[];
10111012

10121013
check_equal(ctrl, &map);

src/librustc/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn path_node(ids: ~[ast::ident]) -> ast::Path {
344344
ast::Path {
345345
span: dummy_sp(),
346346
global: false,
347-
segments: ids.consume_iter().transform(|identifier| ast::PathSegment {
347+
segments: ids.move_iter().map(|identifier| ast::PathSegment {
348348
identifier: identifier,
349349
lifetime: None,
350350
types: opt_vec::Empty,
@@ -356,7 +356,7 @@ fn path_node_global(ids: ~[ast::ident]) -> ast::Path {
356356
ast::Path {
357357
span: dummy_sp(),
358358
global: true,
359-
segments: ids.consume_iter().transform(|identifier| ast::PathSegment {
359+
segments: ids.move_iter().map(|identifier| ast::PathSegment {
360360
identifier: identifier,
361361
lifetime: None,
362362
types: opt_vec::Empty,

src/librustc/metadata/decoder.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,19 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::CrateNum)
335335
let purity = if fam == UnsafeStaticMethod { ast::unsafe_fn } else
336336
{ ast::impure_fn };
337337
// def_static_method carries an optional field of its enclosing
338-
// *trait*, but not an inclosing Impl (if this is an inherent
339-
// static method). So we need to detect whether this is in
340-
// a trait or not, which we do through the mildly hacky
341-
// way of checking whether there is a trait_method_sort.
342-
let trait_did_opt = if reader::maybe_get_doc(
338+
// trait or enclosing impl (if this is an inherent static method).
339+
// So we need to detect whether this is in a trait or not, which
340+
// we do through the mildly hacky way of checking whether there is
341+
// a trait_method_sort.
342+
let provenance = if reader::maybe_get_doc(
343343
item, tag_item_trait_method_sort).is_some() {
344-
Some(item_reqd_and_translated_parent_item(cnum, item))
345-
} else { None };
346-
dl_def(ast::def_static_method(did, trait_did_opt, purity))
344+
ast::FromTrait(item_reqd_and_translated_parent_item(cnum,
345+
item))
346+
} else {
347+
ast::FromImpl(item_reqd_and_translated_parent_item(cnum,
348+
item))
349+
};
350+
dl_def(ast::def_static_method(did, provenance, purity))
347351
}
348352
Type | ForeignType => dl_def(ast::def_ty(did)),
349353
Mod => dl_def(ast::def_mod(did)),

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn parse_path(st: &mut PState) -> @ast::Path {
141141
return @ast::Path {
142142
span: dummy_sp(),
143143
global: false,
144-
segments: idents.consume_iter().transform(|identifier| {
144+
segments: idents.move_iter().map(|identifier| {
145145
ast::PathSegment {
146146
identifier: identifier,
147147
lifetime: None,

0 commit comments

Comments
 (0)