Skip to content

Commit cd61416

Browse files
committed
auto merge of #20387 : nick29581/rust/arrays-2, r=alexcrichton
Closes #19999
2 parents 39d7402 + 2c92dde commit cd61416

Some content is hidden

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

97 files changed

+414
-387
lines changed

src/doc/guide.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1606,18 +1606,18 @@ things. The most basic is the **array**, a fixed-size list of elements of the
16061606
same type. By default, arrays are immutable.
16071607

16081608
```{rust}
1609-
let a = [1i, 2i, 3i]; // a: [int, ..3]
1610-
let mut m = [1i, 2i, 3i]; // mut m: [int, ..3]
1609+
let a = [1i, 2i, 3i]; // a: [int; 3]
1610+
let mut m = [1i, 2i, 3i]; // mut m: [int; 3]
16111611
```
16121612

16131613
There's a shorthand for initializing each element of an array to the same
16141614
value. In this example, each element of `a` will be initialized to `0i`:
16151615

16161616
```{rust}
1617-
let a = [0i, ..20]; // a: [int, ..20]
1617+
let a = [0i; 20]; // a: [int; 20]
16181618
```
16191619

1620-
Arrays have type `[T,..N]`. We'll talk about this `T` notation later, when we
1620+
Arrays have type `[T; N]`. We'll talk about this `T` notation later, when we
16211621
cover generics.
16221622

16231623
You can get the number of elements in an array `a` with `a.len()`, and use

src/doc/reference.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,11 @@ the `static` lifetime, fixed-size arrays, tuples, enum variants, and structs.
14381438
const BIT1: uint = 1 << 0;
14391439
const BIT2: uint = 1 << 1;
14401440
1441-
const BITS: [uint, ..2] = [BIT1, BIT2];
1441+
const BITS: [uint; 2] = [BIT1, BIT2];
14421442
const STRING: &'static str = "bitstring";
14431443
14441444
struct BitsNStrings<'a> {
1445-
mybits: [uint, ..2],
1445+
mybits: [uint; 2],
14461446
mystring: &'a str
14471447
}
14481448
@@ -2923,7 +2923,7 @@ constant expression that can be evaluated at compile time, such as a
29232923
```
29242924
[1i, 2, 3, 4];
29252925
["a", "b", "c", "d"];
2926-
[0i, ..128]; // array with 128 zeros
2926+
[0i; 128]; // array with 128 zeros
29272927
[0u8, 0u8, 0u8, 0u8];
29282928
```
29292929

@@ -3691,7 +3691,7 @@ An example of each kind:
36913691

36923692
```{rust}
36933693
let vec: Vec<int> = vec![1, 2, 3];
3694-
let arr: [int, ..3] = [1, 2, 3];
3694+
let arr: [int; 3] = [1, 2, 3];
36953695
let s: &[int] = vec.as_slice();
36963696
```
36973697

src/libcollections/dlist.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ mod tests {
13221322

13231323
#[bench]
13241324
fn bench_collect_into(b: &mut test::Bencher) {
1325-
let v = &[0i, ..64];
1325+
let v = &[0i; 64];
13261326
b.iter(|| {
13271327
let _: DList<int> = v.iter().map(|x| *x).collect();
13281328
})
@@ -1384,31 +1384,31 @@ mod tests {
13841384

13851385
#[bench]
13861386
fn bench_iter(b: &mut test::Bencher) {
1387-
let v = &[0i, ..128];
1387+
let v = &[0i; 128];
13881388
let m: DList<int> = v.iter().map(|&x|x).collect();
13891389
b.iter(|| {
13901390
assert!(m.iter().count() == 128);
13911391
})
13921392
}
13931393
#[bench]
13941394
fn bench_iter_mut(b: &mut test::Bencher) {
1395-
let v = &[0i, ..128];
1395+
let v = &[0i; 128];
13961396
let mut m: DList<int> = v.iter().map(|&x|x).collect();
13971397
b.iter(|| {
13981398
assert!(m.iter_mut().count() == 128);
13991399
})
14001400
}
14011401
#[bench]
14021402
fn bench_iter_rev(b: &mut test::Bencher) {
1403-
let v = &[0i, ..128];
1403+
let v = &[0i; 128];
14041404
let m: DList<int> = v.iter().map(|&x|x).collect();
14051405
b.iter(|| {
14061406
assert!(m.iter().rev().count() == 128);
14071407
})
14081408
}
14091409
#[bench]
14101410
fn bench_iter_mut_rev(b: &mut test::Bencher) {
1411-
let v = &[0i, ..128];
1411+
let v = &[0i; 128];
14121412
let mut m: DList<int> = v.iter().map(|&x|x).collect();
14131413
b.iter(|| {
14141414
assert!(m.iter_mut().rev().count() == 128);

src/libcollections/slice.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub trait SliceExt<T> for Sized? {
382382
fn get_mut(&mut self, index: uint) -> Option<&mut T>;
383383

384384
/// Work with `self` as a mut slice.
385-
/// Primarily intended for getting a &mut [T] from a [T, ..N].
385+
/// Primarily intended for getting a &mut [T] from a [T; N].
386386
#[stable]
387387
fn as_mut_slice(&mut self) -> &mut [T];
388388

@@ -861,6 +861,7 @@ pub trait CloneSliceExt<T> for Sized? {
861861
fn clone_from_slice(&mut self, &[T]) -> uint;
862862
}
863863

864+
864865
#[unstable = "trait is unstable"]
865866
impl<T: Clone> CloneSliceExt<T> for [T] {
866867
/// Returns a copy of `v`.
@@ -1482,14 +1483,14 @@ mod tests {
14821483

14831484
#[test]
14841485
fn test_is_empty() {
1485-
let xs: [int, ..0] = [];
1486+
let xs: [int; 0] = [];
14861487
assert!(xs.is_empty());
14871488
assert!(![0i].is_empty());
14881489
}
14891490

14901491
#[test]
14911492
fn test_len_divzero() {
1492-
type Z = [i8, ..0];
1493+
type Z = [i8; 0];
14931494
let v0 : &[Z] = &[];
14941495
let v1 : &[Z] = &[[]];
14951496
let v2 : &[Z] = &[[], []];
@@ -1856,7 +1857,7 @@ mod tests {
18561857
#[test]
18571858
fn test_permutations() {
18581859
{
1859-
let v: [int, ..0] = [];
1860+
let v: [int; 0] = [];
18601861
let mut it = v.permutations();
18611862
let (min_size, max_opt) = it.size_hint();
18621863
assert_eq!(min_size, 1);
@@ -2059,7 +2060,7 @@ mod tests {
20592060
}
20602061

20612062
// shouldn't panic
2062-
let mut v: [uint, .. 0] = [];
2063+
let mut v: [uint; 0] = [];
20632064
v.sort();
20642065

20652066
let mut v = [0xDEADBEEFu];
@@ -2071,7 +2072,7 @@ mod tests {
20712072
fn test_sort_stability() {
20722073
for len in range(4i, 25) {
20732074
for _ in range(0u, 10) {
2074-
let mut counts = [0i, .. 10];
2075+
let mut counts = [0i; 10];
20752076

20762077
// create a vector like [(6, 1), (5, 1), (6, 2), ...],
20772078
// where the first item of each tuple is random, but
@@ -2116,28 +2117,28 @@ mod tests {
21162117

21172118
#[test]
21182119
fn test_concat() {
2119-
let v: [Vec<int>, ..0] = [];
2120+
let v: [Vec<int>; 0] = [];
21202121
let c: Vec<int> = v.concat();
21212122
assert_eq!(c, []);
21222123
let d: Vec<int> = [vec![1i], vec![2i,3i]].concat();
21232124
assert_eq!(d, vec![1i, 2, 3]);
21242125

2125-
let v: [&[int], ..2] = [&[1], &[2, 3]];
2126+
let v: [&[int]; 2] = [&[1], &[2, 3]];
21262127
assert_eq!(v.connect(&0), vec![1i, 0, 2, 3]);
2127-
let v: [&[int], ..3] = [&[1i], &[2], &[3]];
2128+
let v: [&[int]; 3] = [&[1i], &[2], &[3]];
21282129
assert_eq!(v.connect(&0), vec![1i, 0, 2, 0, 3]);
21292130
}
21302131

21312132
#[test]
21322133
fn test_connect() {
2133-
let v: [Vec<int>, ..0] = [];
2134+
let v: [Vec<int>; 0] = [];
21342135
assert_eq!(v.connect_vec(&0), vec![]);
21352136
assert_eq!([vec![1i], vec![2i, 3]].connect_vec(&0), vec![1, 0, 2, 3]);
21362137
assert_eq!([vec![1i], vec![2i], vec![3i]].connect_vec(&0), vec![1, 0, 2, 0, 3]);
21372138

2138-
let v: [&[int], ..2] = [&[1], &[2, 3]];
2139+
let v: [&[int]; 2] = [&[1], &[2, 3]];
21392140
assert_eq!(v.connect_vec(&0), vec![1, 0, 2, 3]);
2140-
let v: [&[int], ..3] = [&[1], &[2], &[3]];
2141+
let v: [&[int]; 3] = [&[1], &[2], &[3]];
21412142
assert_eq!(v.connect_vec(&0), vec![1, 0, 2, 0, 3]);
21422143
}
21432144

@@ -2710,7 +2711,7 @@ mod tests {
27102711
}
27112712
assert_eq!(cnt, 11);
27122713

2713-
let xs: [Foo, ..3] = [Foo, Foo, Foo];
2714+
let xs: [Foo; 3] = [Foo, Foo, Foo];
27142715
cnt = 0;
27152716
for f in xs.iter() {
27162717
assert!(*f == Foo);

src/libcollections/str.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ mod tests {
25172517

25182518
#[test]
25192519
fn test_chars_decoding() {
2520-
let mut bytes = [0u8, ..4];
2520+
let mut bytes = [0u8; 4];
25212521
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
25222522
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
25232523
let s = ::core::str::from_utf8(bytes[..len]).unwrap();
@@ -2529,7 +2529,7 @@ mod tests {
25292529

25302530
#[test]
25312531
fn test_chars_rev_decoding() {
2532-
let mut bytes = [0u8, ..4];
2532+
let mut bytes = [0u8; 4];
25332533
for c in range(0u32, 0x110000).filter_map(|c| ::core::char::from_u32(c)) {
25342534
let len = c.encode_utf8(&mut bytes).unwrap_or(0);
25352535
let s = ::core::str::from_utf8(bytes[..len]).unwrap();
@@ -2743,7 +2743,7 @@ mod tests {
27432743
use core::iter::order;
27442744
// official Unicode test data
27452745
// from http://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.txt
2746-
let test_same: [(_, &[_]), .. 325] = [
2746+
let test_same: [(_, &[_]); 325] = [
27472747
("\u{20}\u{20}", &["\u{20}", "\u{20}"]),
27482748
("\u{20}\u{308}\u{20}", &["\u{20}\u{308}", "\u{20}"]),
27492749
("\u{20}\u{D}", &["\u{20}", "\u{D}"]),
@@ -3075,7 +3075,7 @@ mod tests {
30753075
("\u{646}\u{200D}\u{20}", &["\u{646}\u{200D}", "\u{20}"]),
30763076
];
30773077

3078-
let test_diff: [(_, &[_], &[_]), .. 23] = [
3078+
let test_diff: [(_, &[_], &[_]); 23] = [
30793079
("\u{20}\u{903}", &["\u{20}\u{903}"], &["\u{20}", "\u{903}"]), ("\u{20}\u{308}\u{903}",
30803080
&["\u{20}\u{308}\u{903}"], &["\u{20}\u{308}", "\u{903}"]), ("\u{D}\u{308}\u{903}",
30813081
&["\u{D}", "\u{308}\u{903}"], &["\u{D}", "\u{308}", "\u{903}"]), ("\u{A}\u{308}\u{903}",

src/libcollections/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl String {
675675
assert!(idx <= len);
676676
assert!(self.is_char_boundary(idx));
677677
self.vec.reserve(4);
678-
let mut bits = [0, ..4];
678+
let mut bits = [0; 4];
679679
let amt = ch.encode_utf8(&mut bits).unwrap();
680680

681681
unsafe {

src/libcore/array.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ macro_rules! array_impls {
2626
($($N:expr)+) => {
2727
$(
2828
#[stable]
29-
impl<T:Copy> Clone for [T, ..$N] {
30-
fn clone(&self) -> [T, ..$N] {
29+
impl<T:Copy> Clone for [T; $N] {
30+
fn clone(&self) -> [T; $N] {
3131
*self
3232
}
3333
}
3434

3535
#[unstable = "waiting for Show to stabilize"]
36-
impl<T:fmt::Show> fmt::Show for [T, ..$N] {
36+
impl<T:fmt::Show> fmt::Show for [T; $N] {
3737
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3838
fmt::Show::fmt(&self[], f)
3939
}
4040
}
4141

4242
#[stable]
43-
impl<A, B> PartialEq<[B, ..$N]> for [A, ..$N] where A: PartialEq<B> {
43+
impl<A, B> PartialEq<[B; $N]> for [A; $N] where A: PartialEq<B> {
4444
#[inline]
45-
fn eq(&self, other: &[B, ..$N]) -> bool {
45+
fn eq(&self, other: &[B; $N]) -> bool {
4646
self[] == other[]
4747
}
4848
#[inline]
49-
fn ne(&self, other: &[B, ..$N]) -> bool {
49+
fn ne(&self, other: &[B; $N]) -> bool {
5050
self[] != other[]
5151
}
5252
}
5353

5454
#[stable]
55-
impl<'a, A, B, Rhs> PartialEq<Rhs> for [A, ..$N] where
55+
impl<'a, A, B, Rhs> PartialEq<Rhs> for [A; $N] where
5656
A: PartialEq<B>,
5757
Rhs: Deref<[B]>,
5858
{
@@ -63,47 +63,47 @@ macro_rules! array_impls {
6363
}
6464

6565
#[stable]
66-
impl<'a, A, B, Lhs> PartialEq<[B, ..$N]> for Lhs where
66+
impl<'a, A, B, Lhs> PartialEq<[B; $N]> for Lhs where
6767
A: PartialEq<B>,
6868
Lhs: Deref<[A]>
6969
{
7070
#[inline(always)]
71-
fn eq(&self, other: &[B, ..$N]) -> bool { PartialEq::eq(&**self, other[]) }
71+
fn eq(&self, other: &[B; $N]) -> bool { PartialEq::eq(&**self, other[]) }
7272
#[inline(always)]
73-
fn ne(&self, other: &[B, ..$N]) -> bool { PartialEq::ne(&**self, other[]) }
73+
fn ne(&self, other: &[B; $N]) -> bool { PartialEq::ne(&**self, other[]) }
7474
}
7575

7676
#[stable]
77-
impl<T:Eq> Eq for [T, ..$N] { }
77+
impl<T:Eq> Eq for [T; $N] { }
7878

7979
#[stable]
80-
impl<T:PartialOrd> PartialOrd for [T, ..$N] {
80+
impl<T:PartialOrd> PartialOrd for [T; $N] {
8181
#[inline]
82-
fn partial_cmp(&self, other: &[T, ..$N]) -> Option<Ordering> {
82+
fn partial_cmp(&self, other: &[T; $N]) -> Option<Ordering> {
8383
PartialOrd::partial_cmp(&self[], &other[])
8484
}
8585
#[inline]
86-
fn lt(&self, other: &[T, ..$N]) -> bool {
86+
fn lt(&self, other: &[T; $N]) -> bool {
8787
PartialOrd::lt(&self[], &other[])
8888
}
8989
#[inline]
90-
fn le(&self, other: &[T, ..$N]) -> bool {
90+
fn le(&self, other: &[T; $N]) -> bool {
9191
PartialOrd::le(&self[], &other[])
9292
}
9393
#[inline]
94-
fn ge(&self, other: &[T, ..$N]) -> bool {
94+
fn ge(&self, other: &[T; $N]) -> bool {
9595
PartialOrd::ge(&self[], &other[])
9696
}
9797
#[inline]
98-
fn gt(&self, other: &[T, ..$N]) -> bool {
98+
fn gt(&self, other: &[T; $N]) -> bool {
9999
PartialOrd::gt(&self[], &other[])
100100
}
101101
}
102102

103103
#[stable]
104-
impl<T:Ord> Ord for [T, ..$N] {
104+
impl<T:Ord> Ord for [T; $N] {
105105
#[inline]
106-
fn cmp(&self, other: &[T, ..$N]) -> Ordering {
106+
fn cmp(&self, other: &[T; $N]) -> Ordering {
107107
Ord::cmp(&self[], &other[])
108108
}
109109
}

src/libcore/fmt/float.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
123123
// For an f64 the exponent is in the range of [-1022, 1023] for base 2, so
124124
// we may have up to that many digits. Give ourselves some extra wiggle room
125125
// otherwise as well.
126-
let mut buf = [0u8, ..1536];
126+
let mut buf = [0u8; 1536];
127127
let mut end = 0;
128128
let radix_gen: T = cast(radix as int).unwrap();
129129

src/libcore/fmt/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a> Formatter<'a> {
400400
// Writes the sign if it exists, and then the prefix if it was requested
401401
let write_prefix = |&: f: &mut Formatter| {
402402
for c in sign.into_iter() {
403-
let mut b = [0, ..4];
403+
let mut b = [0; 4];
404404
let n = c.encode_utf8(&mut b).unwrap_or(0);
405405
try!(f.buf.write(b[..n]));
406406
}
@@ -505,7 +505,7 @@ impl<'a> Formatter<'a> {
505505
rt::AlignCenter => (padding / 2, (padding + 1) / 2),
506506
};
507507

508-
let mut fill = [0u8, ..4];
508+
let mut fill = [0u8; 4];
509509
let len = self.fill.encode_utf8(&mut fill).unwrap_or(0);
510510

511511
for _ in range(0, pre_pad) {
@@ -606,7 +606,7 @@ impl Show for char {
606606
fn fmt(&self, f: &mut Formatter) -> Result {
607607
use char::Char;
608608

609-
let mut utf8 = [0u8, ..4];
609+
let mut utf8 = [0u8; 4];
610610
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
611611
let s: &str = unsafe { mem::transmute(utf8[..amt]) };
612612
Show::fmt(s, f)

src/libcore/fmt/num.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait GenericRadix {
3737
// characters for a base 2 number.
3838
let zero = Int::zero();
3939
let is_positive = x >= zero;
40-
let mut buf = [0u8, ..64];
40+
let mut buf = [0u8; 64];
4141
let mut curr = buf.len();
4242
let base = cast(self.base()).unwrap();
4343
if is_positive {

0 commit comments

Comments
 (0)