From 41fa4bdf566a7aadd3f2a2314381a4740f1e9aa5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 22 Mar 2013 17:58:50 -0700 Subject: [PATCH 1/5] libcore: Change `[const T]` to `const [T]` everywhere --- src/libcore/at_vec.rs | 22 ++++----- src/libcore/flate.rs | 4 +- src/libcore/hash.rs | 6 +-- src/libcore/io.rs | 18 ++++---- src/libcore/str.rs | 6 +-- src/libcore/to_bytes.rs | 2 +- src/libcore/vec.rs | 46 +++++++++---------- src/libstd/arena.rs | 2 +- src/libstd/net_tcp.rs | 2 +- src/libstd/sha1.rs | 6 +-- src/libstd/sort.rs | 29 +++++++----- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/bench/shootout-spectralnorm.rs | 6 +-- src/test/compile-fail/issue-2150.rs | 2 +- .../compile-fail/mutable-huh-vec-assign.rs | 20 -------- .../tag-that-dare-not-speak-its-name.rs | 2 +- src/test/compile-fail/vec-add.rs | 44 +----------------- src/test/compile-fail/vec-concat-bug.rs | 23 ---------- .../run-pass/coerce-reborrow-imm-vec-arg.rs | 2 +- .../run-pass/coerce-reborrow-imm-vec-rcvr.rs | 2 +- src/test/run-pass/impl-variance.rs | 26 ----------- src/test/run-pass/maybe-mutable.rs | 26 ----------- .../run-pass/mutable-huh-variance-vec1.rs | 23 ---------- .../run-pass/mutable-huh-variance-vec2.rs | 23 ---------- 24 files changed, 85 insertions(+), 259 deletions(-) delete mode 100644 src/test/compile-fail/mutable-huh-vec-assign.rs delete mode 100644 src/test/compile-fail/vec-concat-bug.rs delete mode 100644 src/test/run-pass/impl-variance.rs delete mode 100644 src/test/run-pass/maybe-mutable.rs delete mode 100644 src/test/run-pass/mutable-huh-variance-vec1.rs delete mode 100644 src/test/run-pass/mutable-huh-variance-vec2.rs diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index dbc132899d90e..9a8645723a42f 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -38,7 +38,7 @@ pub mod rustrt { /// Returns the number of elements the vector can hold without reallocating #[inline(always)] -pub fn capacity(v: @[const T]) -> uint { +pub fn capacity(v: @[T]) -> uint { unsafe { let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); @@ -60,7 +60,7 @@ pub fn capacity(v: @[const T]) -> uint { */ #[inline(always)] pub fn build_sized(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] { - let mut vec: @[const A] = @[]; + let mut vec: @[A] = @[]; unsafe { raw::reserve(&mut vec, size); } builder(|+x| unsafe { raw::push(&mut vec, x) }); return unsafe { transmute(vec) }; @@ -102,7 +102,7 @@ pub fn build_sized_opt(size: Option, // Appending #[inline(always)] -pub fn append(lhs: @[T], rhs: &[const T]) -> @[T] { +pub fn append(lhs: @[T], rhs: &const [T]) -> @[T] { do build_sized(lhs.len() + rhs.len()) |push| { for vec::each(lhs) |x| { push(*x); } for uint::range(0, rhs.len()) |i| { push(rhs[i]); } @@ -174,9 +174,9 @@ pub mod traits { use kinds::Copy; use ops::Add; - impl Add<&'self [const T],@[T]> for @[T] { + impl Add<&'self const [T],@[T]> for @[T] { #[inline(always)] - fn add(&self, rhs: & &'self [const T]) -> @[T] { + fn add(&self, rhs: & &'self const [T]) -> @[T] { append(*self, (*rhs)) } } @@ -207,13 +207,13 @@ pub mod raw { * the vector is actually the specified size. */ #[inline(always)] - pub unsafe fn set_len(v: @[const T], new_len: uint) { + pub unsafe fn set_len(v: @[T], new_len: uint) { let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } #[inline(always)] - pub unsafe fn push(v: &mut @[const T], initval: T) { + pub unsafe fn push(v: &mut @[T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { @@ -225,7 +225,7 @@ pub mod raw { } #[inline(always)] // really pretty please - pub unsafe fn push_fast(v: &mut @[const T], initval: T) { + pub unsafe fn push_fast(v: &mut @[T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); @@ -234,7 +234,7 @@ pub mod raw { move_val_init(&mut(*p), initval); } - pub unsafe fn push_slow(v: &mut @[const T], initval: T) { + pub unsafe fn push_slow(v: &mut @[T], initval: T) { reserve_at_least(&mut *v, v.len() + 1u); push_fast(v, initval); } @@ -250,7 +250,7 @@ pub mod raw { * * v - A vector * * n - The number of elements to reserve space for */ - pub unsafe fn reserve(v: &mut @[const T], n: uint) { + pub unsafe fn reserve(v: &mut @[T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(*v) < n { let ptr: **VecRepr = transmute(v); @@ -274,7 +274,7 @@ pub mod raw { * * v - A vector * * n - The number of elements to reserve space for */ - pub unsafe fn reserve_at_least(v: &mut @[const T], n: uint) { + pub unsafe fn reserve_at_least(v: &mut @[T], n: uint) { reserve(v, uint::next_power_of_two(n)); } diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index d9dc89097d03d..b9ba300472950 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -46,7 +46,7 @@ static lz_fast : c_int = 0x1; // LZ with only one probe static lz_norm : c_int = 0x80; // LZ with 128 probes, "normal" static lz_best : c_int = 0xfff; // LZ with 4095 probes, "best" -pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] { +pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] { do vec::as_const_buf(bytes) |b, len| { unsafe { let mut outsz : size_t = 0; @@ -64,7 +64,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] { } } -pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] { +pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] { do vec::as_const_buf(bytes) |b, len| { unsafe { let mut outsz : size_t = 0; diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 1bfa0e9522ddd..c1e9e658df0c7 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -65,7 +65,7 @@ impl HashUtil for A { /// Streaming hash-functions should implement this. pub trait Streaming { - fn input(&self, (&[const u8])); + fn input(&self, (&const [u8])); // These can be refactored some when we have default methods. fn result_bytes(&self) -> ~[u8]; fn result_str(&self) -> ~str; @@ -221,7 +221,7 @@ impl io::Writer for SipState { // Methods for io::writer #[inline(always)] - fn write(&self, msg: &[const u8]) { + fn write(&self, msg: &const [u8]) { let length = msg.len(); self.length += length; @@ -299,7 +299,7 @@ impl io::Writer for SipState { impl Streaming for SipState { #[inline(always)] - fn input(&self, buf: &[const u8]) { + fn input(&self, buf: &const [u8]) { self.write(buf); } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index fb305560ba333..2b66fdb38ab11 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -667,7 +667,7 @@ pub enum WriterType { Screen, File } pub trait Writer { /// Write all of the given bytes. - fn write(&self, v: &[const u8]); + fn write(&self, v: &const [u8]); /// Move the current position within the stream. The second parameter /// determines the position that the first parameter is relative to. @@ -684,7 +684,7 @@ pub trait Writer { } impl Writer for @Writer { - fn write(&self, v: &[const u8]) { self.write(v) } + fn write(&self, v: &const [u8]) { self.write(v) } fn seek(&self, a: int, b: SeekStyle) { self.seek(a, b) } fn tell(&self) -> uint { self.tell() } fn flush(&self) -> int { self.flush() } @@ -692,7 +692,7 @@ impl Writer for @Writer { } impl Writer for Wrapper { - fn write(&self, bs: &[const u8]) { self.base.write(bs); } + fn write(&self, bs: &const [u8]) { self.base.write(bs); } fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); } fn tell(&self) -> uint { self.base.tell() } fn flush(&self) -> int { self.base.flush() } @@ -700,7 +700,7 @@ impl Writer for Wrapper { } impl Writer for *libc::FILE { - fn write(&self, v: &[const u8]) { + fn write(&self, v: &const [u8]) { unsafe { do vec::as_const_buf(v) |vbuf, len| { let nout = libc::fwrite(vbuf as *c_void, @@ -750,7 +750,7 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer { } impl Writer for fd_t { - fn write(&self, v: &[const u8]) { + fn write(&self, v: &const [u8]) { unsafe { let mut count = 0u; do vec::as_const_buf(v) |vbuf, len| { @@ -907,8 +907,10 @@ pub fn u64_to_be_bytes(n: u64, size: uint, } } -pub fn u64_from_be_bytes(data: &[const u8], - start: uint, size: uint) -> u64 { +pub fn u64_from_be_bytes(data: &const [u8], + start: uint, + size: uint) + -> u64 { let mut sz = size; fail_unless!((sz <= 8u)); let mut val = 0_u64; @@ -1140,7 +1142,7 @@ pub struct BytesWriter { } impl Writer for BytesWriter { - fn write(&self, v: &[const u8]) { + fn write(&self, v: &const [u8]) { let v_len = v.len(); let bytes_len = vec::uniq_len(&const self.bytes); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f26d9ee349264..67bd99da5d65b 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -44,7 +44,7 @@ Section: Creating a string * * Fails if invalid UTF-8 */ -pub fn from_bytes(vv: &[const u8]) -> ~str { +pub fn from_bytes(vv: &const [u8]) -> ~str { fail_unless!(is_utf8(vv)); return unsafe { raw::from_bytes(vv) }; } @@ -1574,7 +1574,7 @@ Section: Misc */ /// Determines if a vector of bytes contains valid UTF-8 -pub fn is_utf8(v: &[const u8]) -> bool { +pub fn is_utf8(v: &const [u8]) -> bool { let mut i = 0u; let total = vec::len::(v); while i < total { @@ -2131,7 +2131,7 @@ pub mod raw { } /// Converts a vector of bytes to a string. - pub unsafe fn from_bytes(v: &[const u8]) -> ~str { + pub unsafe fn from_bytes(v: &const [u8]) -> ~str { do vec::as_const_buf(v) |buf, len| { from_buf_len(buf, len) } diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index f379878c8eb0b..32b123979cd5a 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -19,7 +19,7 @@ use io::Writer; use option::{None, Option, Some}; use str; -pub type Cb = &'self fn(buf: &[const u8]) -> bool; +pub type Cb = &'self fn(buf: &const [u8]) -> bool; /** * A trait to implement in order to make a type hashable; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 56d547874d8de..ed80cda0c1be2 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -47,12 +47,12 @@ pub mod rustrt { } /// Returns true if a vector contains no elements -pub fn is_empty(v: &[const T]) -> bool { +pub fn is_empty(v: &const [T]) -> bool { as_const_buf(v, |_p, len| len == 0u) } /// Returns true if two vectors have the same length -pub fn same_length(xs: &[const T], ys: &[const U]) -> bool { +pub fn same_length(xs: &const [T], ys: &const [U]) -> bool { xs.len() == ys.len() } @@ -114,7 +114,7 @@ pub fn capacity(v: &const ~[T]) -> uint { /// Returns the length of a vector #[inline(always)] -pub fn len(v: &[const T]) -> uint { +pub fn len(v: &const [T]) -> uint { as_const_buf(v, |_p, len| len) } @@ -292,8 +292,8 @@ pub fn mut_slice(v: &'r mut [T], start: uint, end: uint) -> &'r mut [T] { /// Return a slice that points into another slice. #[inline(always)] -pub fn const_slice(v: &'r [const T], start: uint, end: uint) - -> &'r [const T] { +pub fn const_slice(v: &'r const [T], start: uint, end: uint) + -> &'r const [T] { fail_unless!(start <= end); fail_unless!(end <= len(v)); do as_const_buf(v) |p, _len| { @@ -624,7 +624,7 @@ fn push_slow(v: &mut ~[T], initval: T) { } #[inline(always)] -pub fn push_all(v: &mut ~[T], rhs: &[const T]) { +pub fn push_all(v: &mut ~[T], rhs: &const [T]) { let new_len = v.len() + rhs.len(); reserve(&mut *v, new_len); @@ -708,7 +708,7 @@ pub fn dedup(v: &mut ~[T]) { // Appending #[inline(always)] -pub fn append(lhs: ~[T], rhs: &[const T]) -> ~[T] { +pub fn append(lhs: ~[T], rhs: &const [T]) -> ~[T] { let mut v = lhs; unsafe { v.push_all(rhs); @@ -1242,7 +1242,7 @@ pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { /** * Convert two vectors to a vector of pairs, by reference. As zip(). */ -pub fn zip_slice(v: &[const T], u: &[const U]) +pub fn zip_slice(v: &const [T], u: &const [U]) -> ~[(T, U)] { let mut zipped = ~[]; let sz = len(v); @@ -1293,7 +1293,7 @@ pub fn reverse(v: &mut [T]) { } /// Returns a vector with the order of elements reversed -pub fn reversed(v: &[const T]) -> ~[T] { +pub fn reversed(v: &const [T]) -> ~[T] { let mut rs: ~[T] = ~[]; let mut i = len::(v); if i == 0 { return (rs); } else { i -= 1; } @@ -1345,7 +1345,7 @@ pub fn reversed(v: &[const T]) -> ~[T] { #[inline(always)] pub fn each(v: &'r [T], f: &fn(&'r T) -> bool) { // ^^^^ - // NB---this CANNOT be &[const T]! The reason + // NB---this CANNOT be &const [T]! The reason // is that you are passing it to `f()` using // an immutable. @@ -1381,7 +1381,7 @@ pub fn each_mut(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) { /// Like `each()`, but for the case where you have a vector that *may or may /// not* have mutable contents. #[inline(always)] -pub fn each_const(v: &[const T], f: &fn(elem: &const T) -> bool) { +pub fn each_const(v: &const [T], f: &fn(elem: &const T) -> bool) { let mut i = 0; let n = v.len(); while i < n { @@ -1508,7 +1508,7 @@ pub fn as_imm_buf(s: &[T], /* NB---this CANNOT be const, see below */ f: &fn(*T, uint) -> U) -> U { - // NB---Do not change the type of s to `&[const T]`. This is + // NB---Do not change the type of s to `&const [T]`. This is // unsound. The reason is that we are going to create immutable pointers // into `s` and pass them to `f()`, but in fact they are potentially // pointing at *mutable memory*. Use `as_const_buf` or `as_mut_buf` @@ -1524,7 +1524,7 @@ pub fn as_imm_buf(s: &[T], /// Similar to `as_imm_buf` but passing a `*const T` #[inline(always)] -pub fn as_const_buf(s: &[const T], f: &fn(*const T, uint) -> U) -> U { +pub fn as_const_buf(s: &const [T], f: &fn(*const T, uint) -> U) -> U { unsafe { let v : *(*const T,uint) = ::cast::reinterpret_cast(&addr_of(&s)); @@ -1685,15 +1685,15 @@ pub mod traits { use ops::Add; use vec::append; - impl Add<&'self [const T],~[T]> for ~[T] { + impl Add<&'self const [T],~[T]> for ~[T] { #[inline(always)] - fn add(&self, rhs: & &'self [const T]) -> ~[T] { + fn add(&self, rhs: & &'self const [T]) -> ~[T] { append(copy *self, (*rhs)) } } } -impl Container for &'self [const T] { +impl Container for &'self const [T] { /// Returns true if a vector contains no elements #[inline] fn is_empty(&const self) -> bool { is_empty(*self) } @@ -1708,7 +1708,7 @@ pub trait CopyableVector { } /// Extension methods for vectors -impl CopyableVector for &'self [const T] { +impl CopyableVector for &'self const [T] { /// Returns a copy of `v`. #[inline] fn to_owned(&self) -> ~[T] { @@ -2041,14 +2041,14 @@ impl Mutable for ~[T] { } pub trait OwnedCopyableVector { - fn push_all(&mut self, rhs: &[const T]); + fn push_all(&mut self, rhs: &const [T]); fn grow(&mut self, n: uint, initval: &T); fn grow_set(&mut self, index: uint, initval: &T, val: T); } impl OwnedCopyableVector for ~[T] { #[inline] - fn push_all(&mut self, rhs: &[const T]) { + fn push_all(&mut self, rhs: &const [T]) { push_all(self, rhs); } @@ -2146,7 +2146,7 @@ pub mod raw { /** see `to_ptr()` */ #[inline(always)] - pub unsafe fn to_const_ptr(v: &[const T]) -> *const T { + pub unsafe fn to_const_ptr(v: &const [T]) -> *const T { let repr: **SliceRepr = ::cast::transmute(&v); ::cast::reinterpret_cast(&addr_of(&((**repr).data))) } @@ -2190,7 +2190,7 @@ pub mod raw { * Unchecked vector indexing. */ #[inline(always)] - pub unsafe fn get(v: &[const T], i: uint) -> T { + pub unsafe fn get(v: &const [T], i: uint) -> T { as_const_buf(v, |p, _len| *ptr::const_offset(p, i)) } @@ -2234,7 +2234,7 @@ pub mod raw { * may overlap. */ #[inline(always)] - pub unsafe fn copy_memory(dst: &mut [T], src: &[const T], + pub unsafe fn copy_memory(dst: &mut [T], src: &const [T], count: uint) { fail_unless!(dst.len() >= count); fail_unless!(src.len() >= count); @@ -2300,7 +2300,7 @@ pub mod bytes { * may overlap. */ #[inline(always)] - pub fn copy_memory(dst: &mut [u8], src: &[const u8], count: uint) { + pub fn copy_memory(dst: &mut [u8], src: &const [u8], count: uint) { // Bound checks are done at vec::raw::copy_memory. unsafe { vec::raw::copy_memory(dst, src, count) } } diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index a26132d92ca01..683e4a629756f 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -101,7 +101,7 @@ impl Drop for Arena { } fn chunk(size: uint, is_pod: bool) -> Chunk { - let mut v: @[const u8] = @[]; + let mut v: @[u8] = @[]; unsafe { at_vec::raw::reserve(&mut v, size); } Chunk { data: unsafe { cast::transmute(v) }, diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index c49f65d0f99b8..c1743c98c9bf1 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -972,7 +972,7 @@ impl io::Reader for TcpSocketBuf { /// Implementation of `io::Reader` trait for a buffered `net::tcp::TcpSocket` impl io::Writer for TcpSocketBuf { - pub fn write(&self, data: &[const u8]) { + pub fn write(&self, data: &const [u8]) { unsafe { let socket_data_ptr = ptr::addr_of(&(*((*(self.data)).sock).socket_data)); diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index 64399defd54f7..b603e2eb1cc66 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -35,7 +35,7 @@ use core::vec; /// The SHA-1 interface trait Sha1 { /// Provide message input as bytes - fn input(&mut self, &[const u8]); + fn input(&mut self, &const [u8]); /// Provide message input as string fn input_str(&mut self, &str); /** @@ -73,7 +73,7 @@ pub fn sha1() -> @Sha1 { computed: bool, work_buf: @mut ~[u32]}; - fn add_input(st: &mut Sha1State, msg: &[const u8]) { + fn add_input(st: &mut Sha1State, msg: &const [u8]) { fail_unless!((!st.computed)); for vec::each_const(msg) |element| { st.msg_block[st.msg_block_idx] = *element; @@ -241,7 +241,7 @@ pub fn sha1() -> @Sha1 { self.h[4] = 0xC3D2E1F0u32; self.computed = false; } - fn input(&mut self, msg: &[const u8]) { add_input(self, msg); } + fn input(&mut self, msg: &const [u8]) { add_input(self, msg); } fn input_str(&mut self, msg: &str) { let bs = str::to_bytes(msg); add_input(self, bs); diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 1dc990526f0b6..7e528f96ca72b 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -24,12 +24,12 @@ type Le = &'self fn(v1: &T, v2: &T) -> bool; * Has worst case O(n log n) performance, best case O(n), but * is not space efficient. This is a stable sort. */ -pub fn merge_sort(v: &[const T], le: Le) -> ~[T] { +pub fn merge_sort(v: &const [T], le: Le) -> ~[T] { type Slice = (uint, uint); unsafe {return merge_sort_(v, (0u, len(v)), le);} - fn merge_sort_(v: &[const T], slice: Slice, le: Le) + fn merge_sort_(v: &const [T], slice: Slice, le: Le) -> ~[T] { let begin = slice.first(); let end = slice.second(); @@ -290,8 +290,10 @@ fn count_run_ascending(array: &mut [T]) -> uint { return run; } -fn gallop_left(key: &const T, array: &[const T], - hint: uint) -> uint { +fn gallop_left(key: &const T, + array: &const [T], + hint: uint) + -> uint { let size = array.len(); fail_unless!(size != 0 && hint < size); @@ -339,8 +341,10 @@ fn gallop_left(key: &const T, array: &[const T], return ofs; } -fn gallop_right(key: &const T, array: &[const T], - hint: uint) -> uint { +fn gallop_right(key: &const T, + array: &const [T], + hint: uint) + -> uint { let size = array.len(); fail_unless!(size != 0 && hint < size); @@ -709,8 +713,11 @@ impl MergeState { } #[inline(always)] -fn copy_vec(dest: &mut [T], s1: uint, - from: &[const T], s2: uint, len: uint) { +fn copy_vec(dest: &mut [T], + s1: uint, + from: &const [T], + s2: uint, + len: uint) { fail_unless!(s1+len <= dest.len() && s2+len <= from.len()); let mut slice = ~[]; @@ -1026,7 +1033,7 @@ mod big_tests { tabulate_managed(low, high); } - fn multiplyVec(arr: &[const T], num: uint) -> ~[T] { + fn multiplyVec(arr: &const [T], num: uint) -> ~[T] { let size = arr.len(); let res = do vec::from_fn(num) |i| { arr[i % size] @@ -1042,7 +1049,7 @@ mod big_tests { } fn tabulate_unique(lo: uint, hi: uint) { - fn isSorted(arr: &[const T]) { + fn isSorted(arr: &const [T]) { for uint::range(0, arr.len()-1) |i| { if arr[i] > arr[i+1] { fail!(~"Array not sorted"); @@ -1114,7 +1121,7 @@ mod big_tests { } fn tabulate_managed(lo: uint, hi: uint) { - fn isSorted(arr: &[const @T]) { + fn isSorted(arr: &const [@T]) { for uint::range(0, arr.len()-1) |i| { if arr[i] > arr[i+1] { fail!(~"Array not sorted"); diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index ada5ff7be2fa8..1764ef48412cc 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -101,7 +101,7 @@ fn chanmb(i: uint, size: uint, depth: uint) -> Line struct Devnull(); impl io::Writer for Devnull { - fn write(&self, _b: &[const u8]) {} + fn write(&self, _b: &const [u8]) {} fn seek(&self, _i: int, _s: io::SeekStyle) {} fn tell(&self) -> uint {0_u} fn flush(&self) -> int {0} diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 2b9a030fdf4ce..6e39b755b22af 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -16,7 +16,7 @@ fn eval_A(i: uint, j: uint) -> float { 1.0/(((i+j)*(i+j+1u)/2u+i+1u) as float) } -fn eval_A_times_u(u: &[const float], Au: &mut [float]) { +fn eval_A_times_u(u: &const [float], Au: &mut [float]) { let N = vec::len(u); let mut i = 0u; while i < N { @@ -30,7 +30,7 @@ fn eval_A_times_u(u: &[const float], Au: &mut [float]) { } } -fn eval_At_times_u(u: &[const float], Au: &mut [float]) { +fn eval_At_times_u(u: &const [float], Au: &mut [float]) { let N = vec::len(u); let mut i = 0u; while i < N { @@ -44,7 +44,7 @@ fn eval_At_times_u(u: &[const float], Au: &mut [float]) { } } -fn eval_AtA_times_u(u: &[const float], AtAu: &mut [float]) { +fn eval_AtA_times_u(u: &const [float], AtAu: &mut [float]) { let mut v = vec::from_elem(vec::len(u), 0.0); eval_A_times_u(u, v); eval_At_times_u(v, AtAu); diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 3ab8f765ad545..9f2f9a855ed52 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn fail_len(v: ~[const int]) -> uint { +fn fail_len(v: ~[int]) -> uint { let mut i = fail!(); for v.each |x| { i += 1u; } //~^ WARNING unreachable statement diff --git a/src/test/compile-fail/mutable-huh-vec-assign.rs b/src/test/compile-fail/mutable-huh-vec-assign.rs deleted file mode 100644 index 83cfd2403563a..0000000000000 --- a/src/test/compile-fail/mutable-huh-vec-assign.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - fn f(&&v: ~[const int]) { - // This shouldn't be possible - v[0] = 1 //~ ERROR assigning to const vec content - } - - let v = ~[0]; - - f(v); -} diff --git a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs index a05d6a324de7b..af99c0e5f2953 100644 --- a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs +++ b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs @@ -15,7 +15,7 @@ extern mod core; -fn last(v: ~[const &T]) -> core::Option { +fn last(v: ~[&T]) -> core::Option { fail!(); } diff --git a/src/test/compile-fail/vec-add.rs b/src/test/compile-fail/vec-add.rs index 0f51d34fc2ff2..f30a050211ec6 100644 --- a/src/test/compile-fail/vec-add.rs +++ b/src/test/compile-fail/vec-add.rs @@ -14,7 +14,7 @@ // the right hand side in all cases. We are getting compiler errors // about this now, so I'm xfailing the test for now. -eholk -fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { +fn add(i: ~[int], mut m: ~[int]) { // Check that: // (1) vectors of any two mutabilities can be added @@ -36,10 +36,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { m + m, m); - add(i + c, - m + c, - c); - add(m + ~[3], //~ ERROR mismatched types m + ~[3], m + ~[3]); @@ -48,12 +44,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { i + ~[3], //~ ERROR mismatched types i + ~[3]); - add(c + ~[3], //~ ERROR mismatched types - //~^ ERROR binary operation + cannot be applied - c + ~[3], //~ ERROR binary operation + cannot be applied - //~^ mismatched types - ~[3]); - add(m + ~[3], //~ ERROR mismatched types m + ~[3], m + ~[3]); @@ -62,12 +52,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { i + ~[3], //~ ERROR mismatched types i + ~[3]); - add(c + ~[3], //~ ERROR binary operation + cannot be applied - //~^ mismatched types - c + ~[3], //~ ERROR binary operation + cannot be applied - //~^ mismatched types - ~[3]); - add(m + i, //~ ERROR mismatched types m + i, m + i); @@ -76,12 +60,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { i + i, //~ ERROR mismatched types i + i); - add(c + i, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c + i, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - i); - add(m + m, //~ ERROR mismatched types m + m, m + m); @@ -89,26 +67,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { add(i + m, i + m, //~ ERROR mismatched types i + m); - - add(c + m, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c + m, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - m); - - add(m + c, //~ ERROR mismatched types - m + c, - m + c); - - add(i + c, - i + c, //~ ERROR mismatched types - i + c); - - add(c + c, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c + c, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c); } fn main() { diff --git a/src/test/compile-fail/vec-concat-bug.rs b/src/test/compile-fail/vec-concat-bug.rs deleted file mode 100644 index 478e01ccd042e..0000000000000 --- a/src/test/compile-fail/vec-concat-bug.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn concat(v: ~[const ~[const T]]) -> ~[T] { - let mut r = ~[]; - - // Earlier versions of our type checker accepted this: - vec::each(v, |inner: &~[T]| { - //~^ ERROR values differ in mutability - r += *inner; true - }); - - return r; -} - -fn main() {} diff --git a/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs b/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs index ad5eb50ccef30..3f12c0d635311 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs @@ -14,7 +14,7 @@ fn sum_imm(y: &[int]) -> int { sum(y) } -fn sum_const(y: &[const int]) -> int { +fn sum_const(y: &const [int]) -> int { sum(y) } diff --git a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs index bf86472d900d7..7dcf49ef1ac44 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs @@ -1,6 +1,6 @@ // xfail-test -fn foo(v: &[const uint]) -> ~[uint] { +fn foo(v: &const [uint]) -> ~[uint] { v.to_vec() } diff --git a/src/test/run-pass/impl-variance.rs b/src/test/run-pass/impl-variance.rs deleted file mode 100644 index 31375edb5de04..0000000000000 --- a/src/test/run-pass/impl-variance.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait foo { - fn foo(&self) -> uint; -} - -impl foo for ~[const T] { - fn foo(&self) -> uint { vec::len(*self) } -} - -pub fn main() { - let v = ~[const 0]; - fail_unless!(v.foo() == 1u); - let v = ~[0]; - fail_unless!(v.foo() == 1u); - let mut v = ~[0]; - fail_unless!(v.foo() == 1u); -} diff --git a/src/test/run-pass/maybe-mutable.rs b/src/test/run-pass/maybe-mutable.rs deleted file mode 100644 index 155046bccccc6..0000000000000 --- a/src/test/run-pass/maybe-mutable.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - - - -// -*- rust -*- -fn len(v: ~[const int]) -> uint { - let mut i = 0u; - while i < vec::len(v) { i += 1u; } - return i; -} - -pub fn main() { - let v0 = ~[1, 2, 3, 4, 5]; - debug!(len(v0)); - let mut v1 = ~[1, 2, 3, 4, 5]; - debug!(len(v1)); -} diff --git a/src/test/run-pass/mutable-huh-variance-vec1.rs b/src/test/run-pass/mutable-huh-variance-vec1.rs deleted file mode 100644 index 8db2705de2b4e..0000000000000 --- a/src/test/run-pass/mutable-huh-variance-vec1.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern: mismatched types - -pub fn main() { - let v = ~[~[0]]; - - // This is ok because the outer vec is covariant with respect - // to the inner vec. If the outer vec was mut then we - // couldn't do this. - fn f(&&v: ~[~[const int]]) { - } - - f(v); -} diff --git a/src/test/run-pass/mutable-huh-variance-vec2.rs b/src/test/run-pass/mutable-huh-variance-vec2.rs deleted file mode 100644 index 7c48744000d4f..0000000000000 --- a/src/test/run-pass/mutable-huh-variance-vec2.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern: mismatched types - -pub fn main() { - let v = ~[~[0]]; - - // This is ok because the outer vec is covariant with respect - // to the inner vec. If the outer vec was mut then we - // couldn't do this. - fn f(&&v: ~[const ~[const int]]) { - } - - f(v); -} From 39900fbc0b7063730266e297d9c1c5b27730cf4e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 22 Mar 2013 18:24:37 -0700 Subject: [PATCH 2/5] libsyntax: Stop parsing `[const T]`. --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index af64bf07b7c3e..63c5d833e7823 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1176,7 +1176,7 @@ pub impl Parser { } else if *self.token == token::LBRACKET { self.bump(); let mutbl = self.parse_mutability(); - if mutbl == m_mutbl { // `m_const` too after snapshot + if mutbl == m_mutbl || mutbl == m_const { self.obsolete(*self.last_span, ObsoleteMutVector); } From b788099dd20899ff04ffc92c39e27a5d22a78995 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 22 Mar 2013 18:52:04 -0700 Subject: [PATCH 3/5] librustc: Remove all uses of the old `[T * N]` fixed-length vector syntax --- src/libcore/cleanup.rs | 10 +++++----- src/libcore/hash.rs | 6 +++--- src/libcore/libc.rs | 8 ++++---- src/libcore/rt/context.rs | 6 +++--- src/libcore/str.rs | 12 ++++++------ src/libcore/sys.rs | 2 +- src/libcore/trie.rs | 2 +- src/libcore/vec.rs | 2 +- src/librustc/middle/typeck/infer/region_inference.rs | 4 ++-- src/libstd/flatpipes.rs | 6 +++--- src/libsyntax/parse/parser.rs | 2 +- src/test/bench/noise.rs | 6 +++--- src/test/bench/sudoku.rs | 6 +++--- src/test/compile-fail/const-cast-wrong-type.rs | 2 +- src/test/compile-fail/evec-subtyping.rs | 6 +++--- src/test/compile-fail/issue-4517.rs | 2 +- src/test/run-pass/const-autoderef.rs | 4 ++-- src/test/run-pass/const-enum-vector.rs | 2 +- src/test/run-pass/const-expr-in-fixed-length-vec.rs | 2 +- src/test/run-pass/const-fields-and-indexing.rs | 2 +- src/test/run-pass/const-region-ptrs-noncopy.rs | 2 +- src/test/run-pass/const-str-ptr.rs | 4 ++-- src/test/run-pass/const-vecs-and-slices.rs | 2 +- src/test/run-pass/evec-internal-boxes.rs | 4 ++-- src/test/run-pass/evec-internal.rs | 10 +++++----- src/test/run-pass/fixed_length_vec_glue.rs | 2 +- src/test/run-pass/issue-3656.rs | 2 +- src/test/run-pass/region-dependent-addr-of.rs | 2 +- src/test/run-pass/vec-fixed-length.rs | 2 +- 29 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 66eeb339700e8..3beb1add3eac9 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -38,12 +38,12 @@ struct MemoryRegion { priv opaque: () } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] struct Registers { - data: [u32 * 16] + data: [u32, ..16] } #[cfg(target_arch="mips")] struct Registers { - data: [u32 * 32] + data: [u32, ..32] } #[cfg(target_arch="x86")] @@ -52,12 +52,12 @@ struct Registers { struct Context { regs: Registers, next: *Context, - pad: [u32 * 3] + pad: [u32, ..3] } #[cfg(target_arch="x86_64")] struct Registers { - data: [u64 * 22] + data: [u64, ..22] } #[cfg(target_arch="x86_64")] @@ -80,7 +80,7 @@ struct Task { // Public fields refcount: intptr_t, // 0 id: TaskID, // 4 - pad: [u32 * 2], // 8 + pad: [u32, ..2], // 8 ctx: Context, // 16 stack_segment: *StackSegment, // 96 runtime_sp: uintptr_t, // 100 diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index c1e9e658df0c7..7b3b49b7ee908 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -162,7 +162,7 @@ struct SipState { mut v1: u64, mut v2: u64, mut v3: u64, - mut tail: [u8 * 8], // unprocessed bytes + mut tail: [u8, ..8], // unprocessed bytes mut ntail: uint, // how many bytes in tail are valid } @@ -369,7 +369,7 @@ impl Streaming for SipState { #[test] pub fn test_siphash() { - let vecs : [[u8 * 8] * 64] = [ + let vecs : [[u8, ..8], ..64] = [ [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], [ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ], [ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ], @@ -443,7 +443,7 @@ pub fn test_siphash() { let stream_inc = &State(k0,k1); let stream_full = &State(k0,k1); - fn to_hex_str(r: &[u8 * 8]) -> ~str { + fn to_hex_str(r: &[u8, ..8]) -> ~str { let mut s = ~""; for vec::each(*r) |b| { s += uint::to_str_radix(*b as uint, 16u); diff --git a/src/libcore/libc.rs b/src/libcore/libc.rs index 47eece81ce1c9..084437354fba4 100644 --- a/src/libcore/libc.rs +++ b/src/libcore/libc.rs @@ -342,7 +342,7 @@ pub mod types { st_mtime_nsec: c_long, st_ctime: time_t, st_ctime_nsec: c_long, - __unused: [c_long * 3], + __unused: [c_long, ..3], } } pub mod posix08 { @@ -430,7 +430,7 @@ pub mod types { st_lspare: int32_t, st_birthtime: time_t, st_birthtime_nsec: c_long, - __unused: [uint8_t * 2], + __unused: [uint8_t, ..2], } } pub mod posix08 { @@ -631,7 +631,7 @@ pub mod types { st_flags: uint32_t, st_gen: uint32_t, st_lspare: int32_t, - st_qspare: [int64_t * 2], + st_qspare: [int64_t, ..2], } } pub mod posix08 { @@ -712,7 +712,7 @@ pub mod types { st_flags: uint32_t, st_gen: uint32_t, st_lspare: int32_t, - st_qspare: [int64_t * 2], + st_qspare: [int64_t, ..2], } } pub mod posix08 { diff --git a/src/libcore/rt/context.rs b/src/libcore/rt/context.rs index 4798399d5e948..d0f052d331920 100644 --- a/src/libcore/rt/context.rs +++ b/src/libcore/rt/context.rs @@ -102,7 +102,7 @@ fn initialize_call_frame(regs: &mut Registers, } #[cfg(target_arch = "x86_64")] -type Registers = [uint * 22]; +type Registers = [uint, ..22]; #[cfg(target_arch = "x86_64")] fn new_regs() -> ~Registers { ~[0, .. 22] } @@ -137,7 +137,7 @@ fn initialize_call_frame(regs: &mut Registers, } #[cfg(target_arch = "arm")] -type Registers = [uint * 32]; +type Registers = [uint, ..32]; #[cfg(target_arch = "arm")] fn new_regs() -> ~Registers { ~[0, .. 32] } @@ -156,7 +156,7 @@ fn initialize_call_frame(regs: &mut Registers, } #[cfg(target_arch = "mips")] -type Registers = [uint * 32]; +type Registers = [uint, ..32]; #[cfg(target_arch = "mips")] fn new_regs() -> ~Registers { ~[0, .. 32] } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 67bd99da5d65b..3c4fa8b185af1 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1921,12 +1921,12 @@ static max_five_b: uint = 67108864u; static tag_six_b: uint = 252u; // Constants used for converting strs to floats -pub static inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8]; -pub static positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8, - 'n' as u8, 'f' as u8]; -pub static negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8, - 'n' as u8, 'f' as u8]; -pub static nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8]; +pub static inf_buf: [u8, ..3] = ['i' as u8, 'n' as u8, 'f' as u8]; +pub static positive_inf_buf: [u8, ..4] = ['+' as u8, 'i' as u8, + 'n' as u8, 'f' as u8]; +pub static negative_inf_buf: [u8, ..4] = ['-' as u8, 'i' as u8, + 'n' as u8, 'f' as u8]; +pub static nan_buf: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8]; /** * Work with the byte buffer of a string. diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 706cb10dba9f7..69991259cf29e 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -194,7 +194,7 @@ pub mod tests { #[test] pub fn nonzero_size_of_basic() { - type Z = [i8 * 0]; + type Z = [i8, ..0]; fail_unless!(size_of::() == 0u); fail_unless!(nonzero_size_of::() == 1u); fail_unless!(nonzero_size_of::() == size_of::()); diff --git a/src/libcore/trie.rs b/src/libcore/trie.rs index 40ef5fee47aa4..405e2e2b174e9 100644 --- a/src/libcore/trie.rs +++ b/src/libcore/trie.rs @@ -217,7 +217,7 @@ pub impl TrieSet { struct TrieNode { count: uint, - children: [Child * SIZE] + children: [Child, ..SIZE] } impl TrieNode { diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ed80cda0c1be2..3fd0b178e05c4 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2642,7 +2642,7 @@ mod tests { #[test] fn test_len_divzero() { - type Z = [i8 * 0]; + type Z = [i8, ..0]; let v0 : &[Z] = &[]; let v1 : &[Z] = &[[]]; let v2 : &[Z] = &[[], []]; diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index f0b5ce9ff60a5..cee197a9462a6 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -1187,11 +1187,11 @@ struct GraphNode { span: span, classification: Classification, value: GraphNodeValue, - head_edge: [uint * 2], + head_edge: [uint, ..2], } struct GraphEdge { - next_edge: [uint * 2], + next_edge: [uint, ..2], constraint: Constraint, span: span, } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 587509af9fa84..01a7cbfe604fa 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -254,7 +254,7 @@ pub trait ByteChan { fn send(&self, val: ~[u8]); } -static CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; +static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; impl,P:BytePort> GenericPort for FlatPort { fn recv(&self) -> T { @@ -921,7 +921,7 @@ mod test { } fn test_try_recv_none3(loader: PortLoader

) { - static CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; + static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; // The control word is followed by garbage let bytes = CONTINUE.to_vec() + ~[0]; let port = loader(bytes); @@ -940,7 +940,7 @@ mod test { fn test_try_recv_none4(+loader: PortLoader

) { fail_unless!(do task::try || { - static CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; + static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; // The control word is followed by a valid length, // then undeserializable garbage let len_bytes = do io::u64_to_be_bytes( diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 63c5d833e7823..caaa1bfa859a0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -251,7 +251,7 @@ pub struct Parser { token: @mut token::Token, span: @mut span, last_span: @mut span, - buffer: @mut [TokenAndSpan * 4], + buffer: @mut [TokenAndSpan, ..4], buffer_start: @mut int, buffer_end: @mut int, tokens_consumed: @mut uint, diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 7993822afd877..d28382abaa386 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -24,8 +24,8 @@ fn gradient(orig: Vec2, grad: Vec2, p: Vec2) -> f32 { } struct Noise2DContext { - rgradients: [Vec2 * 256], - permutations: [int * 256], + rgradients: [Vec2, ..256], + permutations: [int, ..256], } fn Noise2DContext() -> ~Noise2DContext { @@ -50,7 +50,7 @@ pub impl Noise2DContext { } #[inline(always)] - fn get_gradients(&self, gradients: &mut [Vec2 * 4], origins: &mut [Vec2 * 4], x: f32, y: f32) { + fn get_gradients(&self, gradients: &mut [Vec2, ..4], origins: &mut [Vec2, ..4], x: f32, y: f32) { let x0f = f32::floor(x); let y0f = f32::floor(y); let x0 = x0f as int; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 4964cea28ad91..9b6f5dde26163 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -44,7 +44,7 @@ pub impl Sudoku { return Sudoku { grid: g } } - pub fn from_vec(vec: &[[u8 * 9] * 9]) -> Sudoku { + pub fn from_vec(vec: &[[u8, ..9], ..9]) -> Sudoku { let mut g = do vec::from_fn(9u) |i| { do vec::from_fn(9u) |j| { vec[i][j] } }; @@ -182,7 +182,7 @@ impl Colors { } } -static default_sudoku: [[u8 * 9] * 9] = [ +static default_sudoku: [[u8, ..9], ..9] = [ /* 0 1 2 3 4 5 6 7 8 */ /* 0 */ [0u8, 4u8, 0u8, 6u8, 0u8, 0u8, 0u8, 3u8, 2u8], /* 1 */ [0u8, 0u8, 8u8, 0u8, 2u8, 0u8, 0u8, 0u8, 0u8], @@ -196,7 +196,7 @@ static default_sudoku: [[u8 * 9] * 9] = [ ]; #[cfg(test)] -static default_solution: [[u8 * 9] * 9] = [ +static default_solution: [[u8, ..9], ..9] = [ /* 0 1 2 3 4 5 6 7 8 */ /* 0 */ [1u8, 4u8, 9u8, 6u8, 7u8, 5u8, 8u8, 3u8, 2u8], /* 1 */ [5u8, 3u8, 8u8, 1u8, 2u8, 9u8, 7u8, 4u8, 6u8], diff --git a/src/test/compile-fail/const-cast-wrong-type.rs b/src/test/compile-fail/const-cast-wrong-type.rs index 677f4318db759..875358ea14201 100644 --- a/src/test/compile-fail/const-cast-wrong-type.rs +++ b/src/test/compile-fail/const-cast-wrong-type.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static a: [u8 * 3] = ['h' as u8, 'i' as u8, 0 as u8]; +static a: [u8, ..3] = ['h' as u8, 'i' as u8, 0 as u8]; static b: *i8 = &a as *i8; //~ ERROR mismatched types fn main() { diff --git a/src/test/compile-fail/evec-subtyping.rs b/src/test/compile-fail/evec-subtyping.rs index 06baf5c834bf0..f9c8ba01f1805 100644 --- a/src/test/compile-fail/evec-subtyping.rs +++ b/src/test/compile-fail/evec-subtyping.rs @@ -10,7 +10,7 @@ fn wants_box(x: @[uint]) { } fn wants_uniq(x: ~[uint]) { } -fn wants_three(x: [uint * 3]) { } +fn wants_three(x: [uint, ..3]) { } fn has_box(x: @[uint]) { wants_box(x); @@ -24,13 +24,13 @@ fn has_uniq(x: ~[uint]) { wants_three(x); //~ ERROR [] storage differs: expected 3 but found ~ } -fn has_three(x: [uint * 3]) { +fn has_three(x: [uint, ..3]) { wants_box(x); //~ ERROR [] storage differs: expected @ but found 3 wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 3 wants_three(x); } -fn has_four(x: [uint * 4]) { +fn has_four(x: [uint, ..4]) { wants_box(x); //~ ERROR [] storage differs: expected @ but found 4 wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 4 wants_three(x); //~ ERROR [] storage differs: expected 3 but found 4 diff --git a/src/test/compile-fail/issue-4517.rs b/src/test/compile-fail/issue-4517.rs index 18caaa697a17d..23cfeecc520e7 100644 --- a/src/test/compile-fail/issue-4517.rs +++ b/src/test/compile-fail/issue-4517.rs @@ -1,6 +1,6 @@ fn bar(int_param: int) {} fn main() { - let foo: [u8 * 4] = [1u8, ..4u8]; + let foo: [u8, ..4] = [1u8, ..4u8]; bar(foo); //~ ERROR mismatched types: expected `int` but found `[u8 * 4]` (expected int but found vector) } diff --git a/src/test/run-pass/const-autoderef.rs b/src/test/run-pass/const-autoderef.rs index fa482c38d145b..572b961b2f884 100644 --- a/src/test/run-pass/const-autoderef.rs +++ b/src/test/run-pass/const-autoderef.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static A: [u8 * 1] = ['h' as u8]; +static A: [u8, ..1] = ['h' as u8]; static B: u8 = (&A)[0]; -static C: &'static &'static &'static &'static [u8 * 1] = & & & &A; +static C: &'static &'static &'static &'static [u8, ..1] = & & & &A; static D: u8 = (&C)[0]; pub fn main() { diff --git a/src/test/run-pass/const-enum-vector.rs b/src/test/run-pass/const-enum-vector.rs index db7982c451fa0..0e92694dde8ac 100644 --- a/src/test/run-pass/const-enum-vector.rs +++ b/src/test/run-pass/const-enum-vector.rs @@ -9,7 +9,7 @@ // except according to those terms. enum E { V1(int), V0 } -static C: [E * 3] = [V0, V1(0xDEADBEE), V0]; +static C: [E, ..3] = [V0, V1(0xDEADBEE), V0]; pub fn main() { match C[1] { diff --git a/src/test/run-pass/const-expr-in-fixed-length-vec.rs b/src/test/run-pass/const-expr-in-fixed-length-vec.rs index 69585c9d31c9e..dc97c58221983 100644 --- a/src/test/run-pass/const-expr-in-fixed-length-vec.rs +++ b/src/test/run-pass/const-expr-in-fixed-length-vec.rs @@ -14,6 +14,6 @@ fn main() { static FOO: int = 2; - let _v: [int * FOO*3]; + let _v: [int, ..FOO*3]; } diff --git a/src/test/run-pass/const-fields-and-indexing.rs b/src/test/run-pass/const-fields-and-indexing.rs index a3611c5eb2658..658b39509bfbb 100644 --- a/src/test/run-pass/const-fields-and-indexing.rs +++ b/src/test/run-pass/const-fields-and-indexing.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static x : [int * 4] = [1,2,3,4]; +static x : [int, ..4] = [1,2,3,4]; static p : int = x[2]; static y : &'static [int] = &[1,2,3,4]; static q : int = y[2]; diff --git a/src/test/run-pass/const-region-ptrs-noncopy.rs b/src/test/run-pass/const-region-ptrs-noncopy.rs index 23d1d63f18996..46f9fdb08217b 100644 --- a/src/test/run-pass/const-region-ptrs-noncopy.rs +++ b/src/test/run-pass/const-region-ptrs-noncopy.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type Big = [u64 * 8]; +type Big = [u64, ..8]; struct Pair { a: int, b: &'self Big } static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]); static y: &'static Pair<'static> = &Pair {a: 15, b: x}; diff --git a/src/test/run-pass/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index 2560431b53209..1f40c57d851b3 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static a: [u8 * 3] = ['h' as u8, 'i' as u8, 0 as u8]; -static c: &'static [u8 * 3] = &a; +static a: [u8, ..3] = ['h' as u8, 'i' as u8, 0 as u8]; +static c: &'static [u8, ..3] = &a; static b: *u8 = c as *u8; fn main() { diff --git a/src/test/run-pass/const-vecs-and-slices.rs b/src/test/run-pass/const-vecs-and-slices.rs index 736335464b24d..f99f2c17ca5df 100644 --- a/src/test/run-pass/const-vecs-and-slices.rs +++ b/src/test/run-pass/const-vecs-and-slices.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static x : [int * 4] = [1,2,3,4]; +static x : [int, ..4] = [1,2,3,4]; static y : &'static [int] = &[1,2,3,4]; pub fn main() { diff --git a/src/test/run-pass/evec-internal-boxes.rs b/src/test/run-pass/evec-internal-boxes.rs index 657a881089779..ec5c5f01e1597 100644 --- a/src/test/run-pass/evec-internal-boxes.rs +++ b/src/test/run-pass/evec-internal-boxes.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let x : [@int * 5] = [@1,@2,@3,@4,@5]; - let _y : [@int * 5] = [@1,@2,@3,@4,@5]; + let x : [@int, ..5] = [@1,@2,@3,@4,@5]; + let _y : [@int, ..5] = [@1,@2,@3,@4,@5]; let mut z = [@1,@2,@3,@4,@5]; z = x; fail_unless!(*z[0] == 1); diff --git a/src/test/run-pass/evec-internal.rs b/src/test/run-pass/evec-internal.rs index 937912e7baf3e..1c23d5ac810a7 100644 --- a/src/test/run-pass/evec-internal.rs +++ b/src/test/run-pass/evec-internal.rs @@ -14,16 +14,16 @@ // Doesn't work; needs a design decision. pub fn main() { - let x : [int * 5] = [1,2,3,4,5]; - let _y : [int * 5] = [1,2,3,4,5]; + let x : [int, ..5] = [1,2,3,4,5]; + let _y : [int, ..5] = [1,2,3,4,5]; let mut z = [1,2,3,4,5]; z = x; fail_unless!(z[0] == 1); fail_unless!(z[4] == 5); - let a : [int * 5] = [1,1,1,1,1]; - let b : [int * 5] = [2,2,2,2,2]; - let c : [int * 5] = [2,2,2,2,3]; + let a : [int, ..5] = [1,1,1,1,1]; + let b : [int, ..5] = [2,2,2,2,2]; + let c : [int, ..5] = [2,2,2,2,3]; log(debug, a); diff --git a/src/test/run-pass/fixed_length_vec_glue.rs b/src/test/run-pass/fixed_length_vec_glue.rs index 87fdbf071d2af..a8752f444bfd8 100644 --- a/src/test/run-pass/fixed_length_vec_glue.rs +++ b/src/test/run-pass/fixed_length_vec_glue.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Struc { a: u8, b: [int * 3], c: int } +struct Struc { a: u8, b: [int, ..3], c: int } pub fn main() { let arr = [1,2,3]; diff --git a/src/test/run-pass/issue-3656.rs b/src/test/run-pass/issue-3656.rs index edb9278781fd4..b59810fc18875 100644 --- a/src/test/run-pass/issue-3656.rs +++ b/src/test/run-pass/issue-3656.rs @@ -16,7 +16,7 @@ use core::libc::*; struct KEYGEN { - hash_algorithm: [c_uint * 2], + hash_algorithm: [c_uint, ..2], count: uint32_t, salt: *c_void, salt_size: uint32_t, diff --git a/src/test/run-pass/region-dependent-addr-of.rs b/src/test/run-pass/region-dependent-addr-of.rs index 6cad8c74592e4..982515b61219f 100644 --- a/src/test/run-pass/region-dependent-addr-of.rs +++ b/src/test/run-pass/region-dependent-addr-of.rs @@ -14,7 +14,7 @@ struct A { struct B { v1: int, - v2: [int * 3], + v2: [int, ..3], v3: ~[int], v4: C, v5: ~C, diff --git a/src/test/run-pass/vec-fixed-length.rs b/src/test/run-pass/vec-fixed-length.rs index 5d0620be28cfa..5ce1b04dbe9a0 100644 --- a/src/test/run-pass/vec-fixed-length.rs +++ b/src/test/run-pass/vec-fixed-length.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x: [int*4] = [1, 2, 3, 4]; + let x: [int, ..4] = [1, 2, 3, 4]; io::println(fmt!("%d", x[0])); } From f1f99b3834834f3a4747ee33afb079860ba06072 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 22 Mar 2013 19:22:12 -0700 Subject: [PATCH 4/5] librustc: Stop parsing `[T * N]`. --- src/librustc/middle/lang_items.rs | 2 +- src/libsyntax/parse/obsolete.rs | 5 +++++ src/libsyntax/parse/parser.rs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 669587205d546..98d534bab0c93 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -78,7 +78,7 @@ pub enum LangItem { } pub struct LanguageItems { - items: [ Option * 35 ] + items: [Option, ..35] } pub impl LanguageItems { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 0f4de9257c99c..ebe0a17eaa0ae 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -61,6 +61,7 @@ pub enum ObsoleteSyntax { ObsoletePurity, ObsoleteStaticMethod, ObsoleteConstItem, + ObsoleteFixedLengthVectorType, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -209,6 +210,10 @@ pub impl Parser { "`const` items are now `static` items; replace `const` with \ `static`" ), + ObsoleteFixedLengthVectorType => ( + "fixed-length vector notation", + "instead of `[T * N]`, write `[T, ..N]`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index caaa1bfa859a0..45a8cf1ee5fd5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -81,7 +81,7 @@ use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf}; use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer}; use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod}; -use parse::obsolete::{ObsoleteConstItem}; +use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType}; use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; @@ -825,7 +825,7 @@ pub impl Parser { fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> { if self.eat(&token::BINOP(token::STAR)) { - // XXX: Obsolete; remove after snapshot. + self.obsolete(*self.last_span, ObsoleteFixedLengthVectorType); Some(self.parse_expr()) } else if *self.token == token::COMMA && self.look_ahead(1) == token::DOTDOT { From 9e26d16550e35f233692d7d73f59f132f56cfec6 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 24 Mar 2013 21:04:01 -0700 Subject: [PATCH 5/5] librustc: Fix bug with newtype structs containing dtors --- src/librustc/middle/trans/datum.rs | 2 -- src/test/run-pass/newtype-struct-with-dtor.rs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/newtype-struct-with-dtor.rs diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 600f637f72b59..c336fb8bbf96e 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -679,7 +679,6 @@ pub impl Datum { } let repr = adt::represent_type(ccx, self.ty); - fail_unless!(adt::is_newtypeish(repr)); let ty = ty::subst(ccx.tcx, substs, variants[0].args[0]); return match self.mode { ByRef => { @@ -719,7 +718,6 @@ pub impl Datum { } let repr = adt::represent_type(ccx, self.ty); - fail_unless!(adt::is_newtypeish(repr)); let ty = fields[0].mt.ty; return match self.mode { ByRef => { diff --git a/src/test/run-pass/newtype-struct-with-dtor.rs b/src/test/run-pass/newtype-struct-with-dtor.rs new file mode 100644 index 0000000000000..f4a059018d209 --- /dev/null +++ b/src/test/run-pass/newtype-struct-with-dtor.rs @@ -0,0 +1,17 @@ +use core::libc::c_int; +use core::libc; + +pub struct Fd(c_int); + +impl Drop for Fd { + fn finalize(&self) { + unsafe { + libc::close(**self); + } + } +} + +fn main() { +} + +