Skip to content

Commit 8693943

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 3b6314c commit 8693943

Some content is hidden

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

70 files changed

+1128
-526
lines changed

src/libextra/dlist.rs

+9-9
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

+42-19
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
}
@@ -1445,11 +1446,18 @@ mod biguint_tests {
14451446

14461447
#[test]
14471448
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());
1449+
let one: Option<BigUint> = FromStr::from_str("1");
1450+
let two: Option<BigUint> = FromStr::from_str("2");
1451+
let thousand: Option<BigUint> = FromStr::from_str("1000");
1452+
let big: Option<BigUint> =
1453+
FromStr::from_str("1000000000000000000000");
1454+
let bigger: Option<BigUint> =
1455+
FromStr::from_str("1000000000000000000001");
1456+
assert!(one.unwrap().is_odd());
1457+
assert!(two.unwrap().is_even());
1458+
assert!(thousand.unwrap().is_even());
1459+
assert!(big.unwrap().is_even());
1460+
assert!(bigger.unwrap().is_odd());
14531461
assert!((BigUint::from_uint(1) << 64).is_even());
14541462
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
14551463
}
@@ -1534,15 +1542,19 @@ mod biguint_tests {
15341542
}
15351543
}
15361544

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);
1545+
let zed: Option<BigUint> = FromStrRadix::from_str_radix("Z", 10);
1546+
assert_eq!(zed, None);
1547+
let blank: Option<BigUint> = FromStrRadix::from_str_radix("_", 2);
1548+
assert_eq!(blank, None);
1549+
let minus_one: Option<BigUint> = FromStrRadix::from_str_radix("-1",
1550+
10);
1551+
assert_eq!(minus_one, None);
15401552
}
15411553

15421554
#[test]
15431555
fn test_factor() {
15441556
fn factor(n: uint) -> BigUint {
1545-
let mut f= One::one::<BigUint>();
1557+
let mut f: BigUint = One::one();
15461558
for i in range(2, n + 1) {
15471559
// FIXME(#6102): Assignment operator for BigInt causes ICE
15481560
// f *= BigUint::from_uint(i);
@@ -1939,17 +1951,24 @@ mod bigint_tests {
19391951

19401952
#[test]
19411953
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));
1954+
let zero: BigInt = Zero::zero();
1955+
let one: BigInt = One::one();
1956+
assert_eq!((-one).abs_sub(&one), zero);
1957+
let one: BigInt = One::one();
1958+
let zero: BigInt = Zero::zero();
1959+
assert_eq!(one.abs_sub(&one), zero);
1960+
let one: BigInt = One::one();
1961+
let zero: BigInt = Zero::zero();
1962+
assert_eq!(one.abs_sub(&zero), one);
1963+
let one: BigInt = One::one();
1964+
assert_eq!(one.abs_sub(&-one), IntConvertible::from_int(2));
19471965
}
19481966

19491967
#[test]
19501968
fn test_to_str_radix() {
19511969
fn check(n: int, ans: &str) {
1952-
assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10));
1970+
let n: BigInt = IntConvertible::from_int(n);
1971+
assert!(ans == n.to_str_radix(10));
19531972
}
19541973
check(10, "10");
19551974
check(1, "1");
@@ -1962,7 +1981,10 @@ mod bigint_tests {
19621981
#[test]
19631982
fn test_from_str_radix() {
19641983
fn check(s: &str, ans: Option<int>) {
1965-
let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
1984+
let ans = ans.map_move(|n| {
1985+
let x: BigInt = IntConvertible::from_int(n);
1986+
x
1987+
});
19661988
assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
19671989
}
19681990
check("10", Some(10));
@@ -1980,7 +2002,8 @@ mod bigint_tests {
19802002
BigInt::new(Minus, ~[1, 1, 1]));
19812003
assert!(-BigInt::new(Minus, ~[1, 1, 1]) ==
19822004
BigInt::new(Plus, ~[1, 1, 1]));
1983-
assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>());
2005+
let zero: BigInt = Zero::zero();
2006+
assert_eq!(-zero, zero);
19842007
}
19852008
}
19862009

src/libextra/num/rational.rs

+20-9
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

+14-5
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

+1-1
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

+3-2
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn path_node(ids: ~[ast::ident]) -> ast::Path {
387387
ast::Path {
388388
span: dummy_sp(),
389389
global: false,
390-
segments: ids.consume_iter().transform(|identifier| ast::PathSegment {
390+
segments: ids.move_iter().map(|identifier| ast::PathSegment {
391391
identifier: identifier,
392392
lifetime: None,
393393
types: opt_vec::Empty,
@@ -399,7 +399,7 @@ fn path_node_global(ids: ~[ast::ident]) -> ast::Path {
399399
ast::Path {
400400
span: dummy_sp(),
401401
global: true,
402-
segments: ids.consume_iter().transform(|identifier| ast::PathSegment {
402+
segments: ids.move_iter().map(|identifier| ast::PathSegment {
403403
identifier: identifier,
404404
lifetime: None,
405405
types: opt_vec::Empty,

src/librustc/metadata/decoder.rs

+12-8
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

+1-1
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)