1
Fork 0

libcore: Change [const T] to const [T] everywhere

This commit is contained in:
Patrick Walton 2013-03-22 17:58:50 -07:00
parent 5df1aaab98
commit 0d52b22e7b
24 changed files with 85 additions and 259 deletions

View file

@ -38,7 +38,7 @@ pub mod rustrt {
/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pub fn capacity<T>(v: @[const T]) -> uint {
pub fn capacity<T>(v: @[T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::reinterpret_cast(&addr_of(&v));
@ -60,7 +60,7 @@ pub fn capacity<T>(v: @[const T]) -> uint {
*/
#[inline(always)]
pub fn build_sized<A>(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<A>(size: Option<uint>,
// Appending
#[inline(always)]
pub fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
pub fn append<T:Copy>(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<T:Copy> Add<&'self [const T],@[T]> for @[T] {
impl<T:Copy> 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<T>(v: @[const T], new_len: uint) {
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
}
#[inline(always)]
pub unsafe fn push<T>(v: &mut @[const T], initval: T) {
pub unsafe fn push<T>(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<T>(v: &mut @[const T], initval: T) {
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
@ -234,7 +234,7 @@ pub mod raw {
move_val_init(&mut(*p), initval);
}
pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
pub unsafe fn push_slow<T>(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<T>(v: &mut @[const T], n: uint) {
pub unsafe fn reserve<T>(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<T>(v: &mut @[const T], n: uint) {
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
reserve(v, uint::next_power_of_two(n));
}

View file

@ -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;

View file

@ -65,7 +65,7 @@ impl<A:Hash> 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);
}

View file

@ -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<W:Writer,C> Writer for Wrapper<W, C> {
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<W:Writer,C> Writer for Wrapper<W, C> {
}
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<T>(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);

View file

@ -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) };
}
@ -1552,7 +1552,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::<u8>(v);
while i < total {
@ -2099,7 +2099,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)
}

View file

@ -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;

View file

@ -47,12 +47,12 @@ pub mod rustrt {
}
/// Returns true if a vector contains no elements
pub fn is_empty<T>(v: &[const T]) -> bool {
pub fn is_empty<T>(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<T, U>(xs: &[const T], ys: &[const U]) -> bool {
pub fn same_length<T, U>(xs: &const [T], ys: &const [U]) -> bool {
xs.len() == ys.len()
}
@ -114,7 +114,7 @@ pub fn capacity<T>(v: &const ~[T]) -> uint {
/// Returns the length of a vector
#[inline(always)]
pub fn len<T>(v: &[const T]) -> uint {
pub fn len<T>(v: &const [T]) -> uint {
as_const_buf(v, |_p, len| len)
}
@ -292,8 +292,8 @@ pub fn mut_slice<T>(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<T>(v: &'r [const T], start: uint, end: uint)
-> &'r [const T] {
pub fn const_slice<T>(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<T>(v: &mut ~[T], initval: T) {
}
#[inline(always)]
pub fn push_all<T:Copy>(v: &mut ~[T], rhs: &[const T]) {
pub fn push_all<T:Copy>(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<T:Eq>(v: &mut ~[T]) {
// Appending
#[inline(always)]
pub fn append<T:Copy>(lhs: ~[T], rhs: &[const T]) -> ~[T] {
pub fn append<T:Copy>(lhs: ~[T], rhs: &const [T]) -> ~[T] {
let mut v = lhs;
unsafe {
v.push_all(rhs);
@ -1242,7 +1242,7 @@ pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
/**
* Convert two vectors to a vector of pairs, by reference. As zip().
*/
pub fn zip_slice<T:Copy,U:Copy>(v: &[const T], u: &[const U])
pub fn zip_slice<T:Copy,U:Copy>(v: &const [T], u: &const [U])
-> ~[(T, U)] {
let mut zipped = ~[];
let sz = len(v);
@ -1293,7 +1293,7 @@ pub fn reverse<T>(v: &mut [T]) {
}
/// Returns a vector with the order of elements reversed
pub fn reversed<T:Copy>(v: &[const T]) -> ~[T] {
pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
let mut rs: ~[T] = ~[];
let mut i = len::<T>(v);
if i == 0 { return (rs); } else { i -= 1; }
@ -1345,7 +1345,7 @@ pub fn reversed<T:Copy>(v: &[const T]) -> ~[T] {
#[inline(always)]
pub fn each<T>(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<T>(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<T>(v: &[const T], f: &fn(elem: &const T) -> bool) {
pub fn each_const<T>(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<T,U>(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<T,U>(s: &[T],
/// Similar to `as_imm_buf` but passing a `*const T`
#[inline(always)]
pub fn as_const_buf<T,U>(s: &[const T], f: &fn(*const T, uint) -> U) -> U {
pub fn as_const_buf<T,U>(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<T:Copy> Add<&'self [const T],~[T]> for ~[T] {
impl<T:Copy> 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<T> Container for &'self [const T] {
impl<T> 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<T> {
}
/// Extension methods for vectors
impl<T: Copy> CopyableVector<T> for &'self [const T] {
impl<T: Copy> CopyableVector<T> for &'self const [T] {
/// Returns a copy of `v`.
#[inline]
fn to_owned(&self) -> ~[T] {
@ -2041,14 +2041,14 @@ impl<T> Mutable for ~[T] {
}
pub trait OwnedCopyableVector<T:Copy> {
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<T:Copy> OwnedCopyableVector<T> 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<T>(v: &[const T]) -> *const T {
pub unsafe fn to_const_ptr<T>(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<T:Copy>(v: &[const T], i: uint) -> T {
pub unsafe fn get<T:Copy>(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<T>(dst: &mut [T], src: &[const T],
pub unsafe fn copy_memory<T>(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) }
}

View file

@ -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) },

View file

@ -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));

View file

@ -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);

View file

@ -24,12 +24,12 @@ type Le<T> = &'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<T:Copy>(v: &[const T], le: Le<T>) -> ~[T] {
pub fn merge_sort<T:Copy>(v: &const [T], le: Le<T>) -> ~[T] {
type Slice = (uint, uint);
unsafe {return merge_sort_(v, (0u, len(v)), le);}
fn merge_sort_<T:Copy>(v: &[const T], slice: Slice, le: Le<T>)
fn merge_sort_<T:Copy>(v: &const [T], slice: Slice, le: Le<T>)
-> ~[T] {
let begin = slice.first();
let end = slice.second();
@ -290,8 +290,10 @@ fn count_run_ascending<T:Copy + Ord>(array: &mut [T]) -> uint {
return run;
}
fn gallop_left<T:Copy + Ord>(key: &const T, array: &[const T],
hint: uint) -> uint {
fn gallop_left<T:Copy + Ord>(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<T:Copy + Ord>(key: &const T, array: &[const T],
return ofs;
}
fn gallop_right<T:Copy + Ord>(key: &const T, array: &[const T],
hint: uint) -> uint {
fn gallop_right<T:Copy + Ord>(key: &const T,
array: &const [T],
hint: uint)
-> uint {
let size = array.len();
fail_unless!(size != 0 && hint < size);
@ -709,8 +713,11 @@ impl<T:Copy + Ord> MergeState<T> {
}
#[inline(always)]
fn copy_vec<T:Copy>(dest: &mut [T], s1: uint,
from: &[const T], s2: uint, len: uint) {
fn copy_vec<T:Copy>(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 = ~[];
@ -1022,7 +1029,7 @@ mod big_tests {
tabulate_managed(low, high);
}
fn multiplyVec<T:Copy>(arr: &[const T], num: uint) -> ~[T] {
fn multiplyVec<T:Copy>(arr: &const [T], num: uint) -> ~[T] {
let size = arr.len();
let res = do vec::from_fn(num) |i| {
arr[i % size]
@ -1038,7 +1045,7 @@ mod big_tests {
}
fn tabulate_unique(lo: uint, hi: uint) {
fn isSorted<T:Ord>(arr: &[const T]) {
fn isSorted<T:Ord>(arr: &const [T]) {
for uint::range(0, arr.len()-1) |i| {
if arr[i] > arr[i+1] {
fail!(~"Array not sorted");
@ -1110,7 +1117,7 @@ mod big_tests {
}
fn tabulate_managed(lo: uint, hi: uint) {
fn isSorted<T:Ord>(arr: &[const @T]) {
fn isSorted<T:Ord>(arr: &const [@T]) {
for uint::range(0, arr.len()-1) |i| {
if arr[i] > arr[i+1] {
fail!(~"Array not sorted");

View file

@ -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}

View file

@ -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);

View file

@ -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

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
}

View file

@ -15,7 +15,7 @@
extern mod core;
fn last<T>(v: ~[const &T]) -> core::Option<T> {
fn last<T>(v: ~[&T]) -> core::Option<T> {
fail!();
}

View file

@ -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() {

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn concat<T:Copy>(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() {}

View file

@ -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)
}

View file

@ -1,6 +1,6 @@
// xfail-test
fn foo(v: &[const uint]) -> ~[uint] {
fn foo(v: &const [uint]) -> ~[uint] {
v.to_vec()
}

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait foo {
fn foo(&self) -> uint;
}
impl<T> 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);
}

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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));
}

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
}

View file

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
}