rustc: Remove ~[T] from the language

The following features have been removed

* box [a, b, c]
* ~[a, b, c]
* box [a, ..N]
* ~[a, ..N]
* ~[T] (as a type)
* deprecated_owned_vector lint

All users of ~[T] should move to using Vec<T> instead.
This commit is contained in:
Alex Crichton 2014-06-06 10:27:49 -07:00
parent f9260d41d6
commit 3316b1eb7c
68 changed files with 355 additions and 823 deletions

View File

@ -155,24 +155,6 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uin
alloc as *mut u8
}
// hack for libcore
#[no_mangle]
#[doc(hidden)]
#[deprecated]
#[cfg(not(test))]
pub unsafe extern "C" fn rust_allocate(size: uint, align: uint) -> *mut u8 {
allocate(size, align)
}
// hack for libcore
#[no_mangle]
#[doc(hidden)]
#[deprecated]
#[cfg(not(test))]
pub unsafe extern "C" fn rust_deallocate(ptr: *mut u8, size: uint, align: uint) {
deallocate(ptr, size, align)
}
#[cfg(test)]
mod bench {
extern crate test;
@ -184,11 +166,4 @@ mod bench {
box 10
})
}
#[bench]
fn alloc_owned_big(b: &mut Bencher) {
b.iter(|| {
box [10, ..1000]
})
}
}

View File

@ -213,13 +213,6 @@ impl<'a, S: Writer, T: Hash<S>> Hash<S> for &'a mut [T] {
}
}
impl<S: Writer, T: Hash<S>> Hash<S> for ~[T] {
#[inline]
fn hash(&self, state: &mut S) {
self.as_slice().hash(state);
}
}
impl<S: Writer, T: Hash<S>> Hash<S> for Vec<T> {
#[inline]
fn hash(&self, state: &mut S) {

View File

@ -276,6 +276,7 @@ mod tests {
use str::Str;
use string::String;
use slice::{Vector, ImmutableVector};
use vec::Vec;
use super::super::{Hash, Writer};
use super::{SipState, hash, hash_with_keys};
@ -376,8 +377,8 @@ mod tests {
s
}
fn result_bytes(h: u64) -> ~[u8] {
box [(h >> 0) as u8,
fn result_bytes(h: u64) -> Vec<u8> {
vec![(h >> 0) as u8,
(h >> 8) as u8,
(h >> 16) as u8,
(h >> 24) as u8,

View File

@ -101,11 +101,8 @@ There are a number of free functions that create or take vectors, for example:
use core::prelude::*;
use alloc::heap::{allocate, deallocate};
use core::cmp;
use core::finally::try_finally;
use core::mem::size_of;
use core::mem::transmute;
use core::mem;
use core::ptr;
use core::iter::{range_step, MultiplicativeIterator};
@ -255,18 +252,18 @@ impl Iterator<(uint, uint)> for ElementSwaps {
/// Generates even and odd permutations alternately.
pub struct Permutations<T> {
swaps: ElementSwaps,
v: ~[T],
v: Vec<T>,
}
impl<T: Clone> Iterator<~[T]> for Permutations<T> {
impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
#[inline]
fn next(&mut self) -> Option<~[T]> {
fn next(&mut self) -> Option<Vec<T>> {
match self.swaps.next() {
None => None,
Some((0,0)) => Some(self.v.clone()),
Some((a, b)) => {
let elt = self.v.clone();
self.v.swap(a, b);
self.v.as_mut_slice().swap(a, b);
Some(elt)
}
}
@ -281,73 +278,20 @@ impl<T: Clone> Iterator<~[T]> for Permutations<T> {
/// Extension methods for vector slices with cloneable elements
pub trait CloneableVector<T> {
/// Copy `self` into a new owned vector
fn to_owned(&self) -> ~[T];
fn to_owned(&self) -> Vec<T>;
/// Convert `self` into an owned vector, not making a copy if possible.
fn into_owned(self) -> ~[T];
fn into_owned(self) -> Vec<T>;
}
/// Extension methods for vector slices
impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
/// Returns a copy of `v`.
#[inline]
fn to_owned(&self) -> ~[T] {
use RawVec = core::raw::Vec;
use core::num::{CheckedAdd, CheckedMul};
use core::ptr;
let len = self.len();
let data_size = len.checked_mul(&mem::size_of::<T>());
let data_size = data_size.expect("overflow in to_owned()");
let size = mem::size_of::<RawVec<()>>().checked_add(&data_size);
let size = size.expect("overflow in to_owned()");
unsafe {
// this should pass the real required alignment
let ret = allocate(size, 8) as *mut RawVec<()>;
let a_size = mem::size_of::<T>();
let a_size = if a_size == 0 {1} else {a_size};
(*ret).fill = len * a_size;
(*ret).alloc = len * a_size;
// Be careful with the following loop. We want it to be optimized
// to a memcpy (or something similarly fast) when T is Copy. LLVM
// is easily confused, so any extra operations during the loop can
// prevent this optimization.
let mut i = 0;
let p = &mut (*ret).data as *mut _ as *mut T;
try_finally(
&mut i, (),
|i, ()| while *i < len {
ptr::write(
&mut(*p.offset(*i as int)),
self.unsafe_ref(*i).clone());
*i += 1;
},
|i| if *i < len {
// we must be failing, clean up after ourselves
for j in range(0, *i as int) {
ptr::read(&*p.offset(j));
}
// FIXME: #13994 (should pass align and size here)
deallocate(ret as *mut u8, 0, 8);
});
mem::transmute(ret)
}
}
fn to_owned(&self) -> Vec<T> { Vec::from_slice(*self) }
#[inline(always)]
fn into_owned(self) -> ~[T] { self.to_owned() }
}
/// Extension methods for owned vectors
impl<T: Clone> CloneableVector<T> for ~[T] {
#[inline]
fn to_owned(&self) -> ~[T] { self.clone() }
#[inline(always)]
fn into_owned(self) -> ~[T] { self }
fn into_owned(self) -> Vec<T> { self.to_owned() }
}
/// Extension methods for vectors containing `Clone` elements.
@ -387,57 +331,6 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
}
/// Extension methods for owned vectors.
pub trait OwnedVector<T> {
/// Creates a consuming iterator, that is, one that moves each
/// value out of the vector (from start to end). The vector cannot
/// be used after calling this.
///
/// # Examples
///
/// ```rust
/// let v = ~["a".to_string(), "b".to_string()];
/// for s in v.move_iter() {
/// // s has type ~str, not &~str
/// println!("{}", s);
/// }
/// ```
fn move_iter(self) -> MoveItems<T>;
/**
* Partitions the vector into two vectors `(A,B)`, where all
* elements of `A` satisfy `f` and all elements of `B` do not.
*/
fn partition(self, f: |&T| -> bool) -> (Vec<T>, Vec<T>);
}
impl<T> OwnedVector<T> for ~[T] {
#[inline]
fn move_iter(self) -> MoveItems<T> {
unsafe {
let iter = transmute(self.iter());
let ptr = transmute(self);
MoveItems { allocation: ptr, iter: iter }
}
}
#[inline]
fn partition(self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
let mut lefts = Vec::new();
let mut rights = Vec::new();
for elt in self.move_iter() {
if f(&elt) {
lefts.push(elt);
} else {
rights.push(elt);
}
}
(lefts, rights)
}
}
fn insertion_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
let len = v.len() as int;
let buf_v = v.as_mut_ptr();
@ -676,7 +569,7 @@ pub trait MutableVectorAllocating<'a, T> {
* * start - The index into `src` to start copying from
* * end - The index into `str` to stop copying from
*/
fn move_from(self, src: ~[T], start: uint, end: uint) -> uint;
fn move_from(self, src: Vec<T>, start: uint, end: uint) -> uint;
}
impl<'a,T> MutableVectorAllocating<'a, T> for &'a mut [T] {
@ -686,7 +579,7 @@ impl<'a,T> MutableVectorAllocating<'a, T> for &'a mut [T] {
}
#[inline]
fn move_from(self, mut src: ~[T], start: uint, end: uint) -> uint {
fn move_from(self, mut src: Vec<T>, start: uint, end: uint) -> uint {
for (a, b) in self.mut_iter().zip(src.mut_slice(start, end).mut_iter()) {
mem::swap(a, b);
}
@ -815,47 +708,6 @@ pub mod raw {
pub use core::slice::raw::{shift_ptr, pop_ptr};
}
/// An iterator that moves out of a vector.
pub struct MoveItems<T> {
allocation: *mut u8, // the block of memory allocated for the vector
iter: Items<'static, T>
}
impl<T> Iterator<T> for MoveItems<T> {
#[inline]
fn next(&mut self) -> Option<T> {
unsafe {
self.iter.next().map(|x| ptr::read(x))
}
}
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
self.iter.size_hint()
}
}
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
unsafe {
self.iter.next_back().map(|x| ptr::read(x))
}
}
}
#[unsafe_destructor]
impl<T> Drop for MoveItems<T> {
fn drop(&mut self) {
// destroy the remaining elements
for _x in *self {}
unsafe {
// FIXME: #13994 (should pass align and size here)
deallocate(self.allocation, 0, 8)
}
}
}
#[cfg(test)]
mod tests {
use std::cell::Cell;
@ -944,92 +796,92 @@ mod tests {
#[test]
fn test_get() {
let mut a = box [11];
assert_eq!(a.get(1), None);
a = box [11, 12];
assert_eq!(a.get(1).unwrap(), &12);
a = box [11, 12, 13];
assert_eq!(a.get(1).unwrap(), &12);
let mut a = vec![11];
assert_eq!(a.as_slice().get(1), None);
a = vec![11, 12];
assert_eq!(a.as_slice().get(1).unwrap(), &12);
a = vec![11, 12, 13];
assert_eq!(a.as_slice().get(1).unwrap(), &12);
}
#[test]
fn test_head() {
let mut a = box [];
assert_eq!(a.head(), None);
a = box [11];
assert_eq!(a.head().unwrap(), &11);
a = box [11, 12];
assert_eq!(a.head().unwrap(), &11);
let mut a = vec![];
assert_eq!(a.as_slice().head(), None);
a = vec![11];
assert_eq!(a.as_slice().head().unwrap(), &11);
a = vec![11, 12];
assert_eq!(a.as_slice().head().unwrap(), &11);
}
#[test]
fn test_tail() {
let mut a = box [11];
let mut a = vec![11];
assert_eq!(a.tail(), &[]);
a = box [11, 12];
a = vec![11, 12];
assert_eq!(a.tail(), &[12]);
}
#[test]
#[should_fail]
fn test_tail_empty() {
let a: ~[int] = box [];
let a: Vec<int> = vec![];
a.tail();
}
#[test]
fn test_tailn() {
let mut a = box [11, 12, 13];
let mut a = vec![11, 12, 13];
assert_eq!(a.tailn(0), &[11, 12, 13]);
a = box [11, 12, 13];
a = vec![11, 12, 13];
assert_eq!(a.tailn(2), &[13]);
}
#[test]
#[should_fail]
fn test_tailn_empty() {
let a: ~[int] = box [];
let a: Vec<int> = vec![];
a.tailn(2);
}
#[test]
fn test_init() {
let mut a = box [11];
let mut a = vec![11];
assert_eq!(a.init(), &[]);
a = box [11, 12];
a = vec![11, 12];
assert_eq!(a.init(), &[11]);
}
#[test]
#[should_fail]
fn test_init_empty() {
let a: ~[int] = box [];
let a: Vec<int> = vec![];
a.init();
}
#[test]
fn test_initn() {
let mut a = box [11, 12, 13];
assert_eq!(a.initn(0), &[11, 12, 13]);
a = box [11, 12, 13];
assert_eq!(a.initn(2), &[11]);
let mut a = vec![11, 12, 13];
assert_eq!(a.as_slice().initn(0), &[11, 12, 13]);
a = vec![11, 12, 13];
assert_eq!(a.as_slice().initn(2), &[11]);
}
#[test]
#[should_fail]
fn test_initn_empty() {
let a: ~[int] = box [];
a.initn(2);
let a: Vec<int> = vec![];
a.as_slice().initn(2);
}
#[test]
fn test_last() {
let mut a = box [];
assert_eq!(a.last(), None);
a = box [11];
assert_eq!(a.last().unwrap(), &11);
a = box [11, 12];
assert_eq!(a.last().unwrap(), &12);
let mut a = vec![];
assert_eq!(a.as_slice().last(), None);
a = vec![11];
assert_eq!(a.as_slice().last().unwrap(), &11);
a = vec![11, 12];
assert_eq!(a.as_slice().last().unwrap(), &12);
}
#[test]
@ -1038,6 +890,7 @@ mod tests {
let vec_fixed = [1, 2, 3, 4];
let v_a = vec_fixed.slice(1u, vec_fixed.len()).to_owned();
assert_eq!(v_a.len(), 3u);
let v_a = v_a.as_slice();
assert_eq!(v_a[0], 2);
assert_eq!(v_a[1], 3);
assert_eq!(v_a[2], 4);
@ -1046,13 +899,15 @@ mod tests {
let vec_stack = &[1, 2, 3];
let v_b = vec_stack.slice(1u, 3u).to_owned();
assert_eq!(v_b.len(), 2u);
let v_b = v_b.as_slice();
assert_eq!(v_b[0], 2);
assert_eq!(v_b[1], 3);
// Test `Box<[T]>`
let vec_unique = box [1, 2, 3, 4, 5, 6];
let vec_unique = vec![1, 2, 3, 4, 5, 6];
let v_d = vec_unique.slice(1u, 6u).to_owned();
assert_eq!(v_d.len(), 5u);
let v_d = v_d.as_slice();
assert_eq!(v_d[0], 2);
assert_eq!(v_d[1], 3);
assert_eq!(v_d[2], 4);
@ -1295,15 +1150,15 @@ mod tests {
let (min_size, max_opt) = it.size_hint();
assert_eq!(min_size, 3*2);
assert_eq!(max_opt.unwrap(), 3*2);
assert_eq!(it.next(), Some(box [1,2,3]));
assert_eq!(it.next(), Some(box [1,3,2]));
assert_eq!(it.next(), Some(box [3,1,2]));
assert_eq!(it.next(), Some(vec![1,2,3]));
assert_eq!(it.next(), Some(vec![1,3,2]));
assert_eq!(it.next(), Some(vec![3,1,2]));
let (min_size, max_opt) = it.size_hint();
assert_eq!(min_size, 3);
assert_eq!(max_opt.unwrap(), 3);
assert_eq!(it.next(), Some(box [3,2,1]));
assert_eq!(it.next(), Some(box [2,3,1]));
assert_eq!(it.next(), Some(box [2,1,3]));
assert_eq!(it.next(), Some(vec![3,2,1]));
assert_eq!(it.next(), Some(vec![2,3,1]));
assert_eq!(it.next(), Some(vec![2,1,3]));
assert_eq!(it.next(), None);
}
{
@ -1378,11 +1233,11 @@ mod tests {
fn test_position_elem() {
assert!([].position_elem(&1).is_none());
let v1 = box [1, 2, 3, 3, 2, 5];
assert_eq!(v1.position_elem(&1), Some(0u));
assert_eq!(v1.position_elem(&2), Some(1u));
assert_eq!(v1.position_elem(&5), Some(5u));
assert!(v1.position_elem(&4).is_none());
let v1 = vec![1, 2, 3, 3, 2, 5];
assert_eq!(v1.as_slice().position_elem(&1), Some(0u));
assert_eq!(v1.as_slice().position_elem(&2), Some(1u));
assert_eq!(v1.as_slice().position_elem(&5), Some(5u));
assert!(v1.as_slice().position_elem(&4).is_none());
}
#[test]
@ -1432,14 +1287,14 @@ mod tests {
#[test]
fn test_reverse() {
let mut v: ~[int] = box [10, 20];
assert_eq!(v[0], 10);
assert_eq!(v[1], 20);
let mut v: Vec<int> = vec![10, 20];
assert_eq!(*v.get(0), 10);
assert_eq!(*v.get(1), 20);
v.reverse();
assert_eq!(v[0], 20);
assert_eq!(v[1], 10);
assert_eq!(*v.get(0), 20);
assert_eq!(*v.get(1), 10);
let mut v3: ~[int] = box [];
let mut v3: Vec<int> = vec![];
v3.reverse();
assert!(v3.is_empty());
}
@ -1505,10 +1360,10 @@ mod tests {
#[test]
fn test_partition() {
assert_eq!((box []).partition(|x: &int| *x < 3), (vec![], vec![]));
assert_eq!((box [1, 2, 3]).partition(|x: &int| *x < 4), (vec![1, 2, 3], vec![]));
assert_eq!((box [1, 2, 3]).partition(|x: &int| *x < 2), (vec![1], vec![2, 3]));
assert_eq!((box [1, 2, 3]).partition(|x: &int| *x < 0), (vec![], vec![1, 2, 3]));
assert_eq!((vec![]).partition(|x: &int| *x < 3), (vec![], vec![]));
assert_eq!((vec![1, 2, 3]).partition(|x: &int| *x < 4), (vec![1, 2, 3], vec![]));
assert_eq!((vec![1, 2, 3]).partition(|x: &int| *x < 2), (vec![1], vec![2, 3]));
assert_eq!((vec![1, 2, 3]).partition(|x: &int| *x < 0), (vec![], vec![1, 2, 3]));
}
#[test]
@ -1521,19 +1376,19 @@ mod tests {
#[test]
fn test_concat() {
let v: [~[int], ..0] = [];
let v: [Vec<int>, ..0] = [];
assert_eq!(v.concat_vec(), vec![]);
assert_eq!([box [1], box [2,3]].concat_vec(), vec![1, 2, 3]);
assert_eq!([vec![1], vec![2,3]].concat_vec(), vec![1, 2, 3]);
assert_eq!([&[1], &[2,3]].concat_vec(), vec![1, 2, 3]);
}
#[test]
fn test_connect() {
let v: [~[int], ..0] = [];
let v: [Vec<int>, ..0] = [];
assert_eq!(v.connect_vec(&0), vec![]);
assert_eq!([box [1], box [2, 3]].connect_vec(&0), vec![1, 0, 2, 3]);
assert_eq!([box [1], box [2], box [3]].connect_vec(&0), vec![1, 0, 2, 0, 3]);
assert_eq!([vec![1], vec![2, 3]].connect_vec(&0), vec![1, 0, 2, 3]);
assert_eq!([vec![1], vec![2], vec![3]].connect_vec(&0), vec![1, 0, 2, 0, 3]);
assert_eq!([&[1], &[2, 3]].connect_vec(&0), vec![1, 0, 2, 3]);
assert_eq!([&[1], &[2], &[3]].connect_vec(&0), vec![1, 0, 2, 0, 3]);
@ -1808,13 +1663,13 @@ mod tests {
#[test]
fn test_move_iterator() {
let xs = box [1u,2,3,4,5];
let xs = vec![1u,2,3,4,5];
assert_eq!(xs.move_iter().fold(0, |a: uint, b: uint| 10*a + b), 12345);
}
#[test]
fn test_move_rev_iterator() {
let xs = box [1u,2,3,4,5];
let xs = vec![1u,2,3,4,5];
assert_eq!(xs.move_iter().rev().fold(0, |a: uint, b: uint| 10*a + b), 54321);
}
@ -1927,19 +1782,19 @@ mod tests {
#[test]
fn test_move_from() {
let mut a = [1,2,3,4,5];
let b = box [6,7,8];
let b = vec![6,7,8];
assert_eq!(a.move_from(b, 0, 3), 3);
assert!(a == [6,7,8,4,5]);
let mut a = [7,2,8,1];
let b = box [3,1,4,1,5,9];
let b = vec![3,1,4,1,5,9];
assert_eq!(a.move_from(b, 0, 6), 4);
assert!(a == [3,1,4,1]);
let mut a = [1,2,3,4];
let b = box [5,6,7,8,9,0];
let b = vec![5,6,7,8,9,0];
assert_eq!(a.move_from(b, 2, 3), 1);
assert!(a == [7,2,3,4]);
let mut a = [1,2,3,4,5];
let b = box [5,6,7,8,9,0];
let b = vec![5,6,7,8,9,0];
assert_eq!(a.mut_slice(2,4).move_from(b,1,6), 2);
assert!(a == [1,2,6,7,5]);
}
@ -1972,11 +1827,11 @@ mod tests {
assert_eq!(format!("{}", x.as_slice()), x_str);
})
)
let empty: ~[int] = box [];
let empty: Vec<int> = vec![];
test_show_vec!(empty, "[]".to_string());
test_show_vec!(box [1], "[1]".to_string());
test_show_vec!(box [1, 2, 3], "[1, 2, 3]".to_string());
test_show_vec!(box [box [], box [1u], box [1u, 1u]],
test_show_vec!(vec![1], "[1]".to_string());
test_show_vec!(vec![1, 2, 3], "[1, 2, 3]".to_string());
test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]],
"[[], [1], [1, 1]]".to_string());
let empty_mut: &mut [int] = &mut[];
@ -1997,7 +1852,6 @@ mod tests {
);
t!(&[int]);
t!(~[int]);
t!(Vec<int>);
}
@ -2392,13 +2246,6 @@ mod bench {
});
}
#[bench]
fn zero_1kb_fixed_repeat(b: &mut Bencher) {
b.iter(|| {
box [0u8, ..1024]
});
}
#[bench]
fn zero_1kb_loop_set(b: &mut Bencher) {
b.iter(|| {

View File

@ -707,7 +707,7 @@ pub mod raw {
use str::StrAllocating;
unsafe {
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
let a = vec![65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
let b = a.as_ptr();
let c = from_buf_len(b, 3u);
assert_eq!(c, "AAA".to_string());
@ -1124,7 +1124,7 @@ mod tests {
assert!(half_a_million_letter_a() ==
unsafe {raw::slice_bytes(letters.as_slice(),
0u,
500000)}.to_owned());
500000)}.to_string());
}
#[test]
@ -1219,7 +1219,7 @@ mod tests {
assert_eq!("", data.slice(3, 3));
assert_eq!("", data.slice(30, 33));
fn a_million_letter_X() -> String {
fn a_million_letter_x() -> String {
let mut i = 0;
let mut rs = String::new();
while i < 100000 {
@ -1228,7 +1228,7 @@ mod tests {
}
rs
}
fn half_a_million_letter_X() -> String {
fn half_a_million_letter_x() -> String {
let mut i = 0;
let mut rs = String::new();
while i < 100000 {
@ -1237,9 +1237,9 @@ mod tests {
}
rs
}
let letters = a_million_letter_X();
assert!(half_a_million_letter_X() ==
letters.as_slice().slice(0u, 3u * 500000u).to_owned());
let letters = a_million_letter_x();
assert!(half_a_million_letter_x() ==
letters.as_slice().slice(0u, 3u * 500000u).to_string());
}
#[test]
@ -1464,7 +1464,7 @@ mod tests {
#[test]
fn test_raw_from_c_str() {
unsafe {
let a = box [65, 65, 65, 65, 65, 65, 65, 0];
let a = vec![65, 65, 65, 65, 65, 65, 65, 0];
let b = a.as_ptr();
let c = raw::from_c_str(b);
assert_eq!(c, "AAAAAAA".to_string());
@ -1682,7 +1682,7 @@ mod tests {
#[test]
fn test_char_at() {
let s = "ศไทย中华Việt Nam";
let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let v = vec!['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = 0;
for ch in v.iter() {
assert!(s.char_at(pos) == *ch);
@ -1693,7 +1693,7 @@ mod tests {
#[test]
fn test_char_at_reverse() {
let s = "ศไทย中华Việt Nam";
let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let v = vec!['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = s.len();
for ch in v.iter().rev() {
assert!(s.char_at_reverse(pos) == *ch);
@ -1756,7 +1756,7 @@ mod tests {
#[test]
fn test_iterator() {
let s = "ศไทย中华Việt Nam";
let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let v = ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = 0;
let mut it = s.chars();
@ -1771,7 +1771,7 @@ mod tests {
#[test]
fn test_rev_iterator() {
let s = "ศไทย中华Việt Nam";
let v = box ['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ'];
let v = ['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ'];
let mut pos = 0;
let mut it = s.chars().rev();

View File

@ -13,7 +13,6 @@
use core::prelude::*;
use alloc::heap::{allocate, reallocate, deallocate};
use RawVec = core::raw::Vec;
use core::raw::Slice;
use core::cmp::max;
use core::default::Default;
@ -25,7 +24,7 @@ use core::ptr;
use core::uint;
use {Collection, Mutable};
use slice::{MutableOrdVector, OwnedVector, MutableVectorAllocating};
use slice::{MutableOrdVector, MutableVectorAllocating, CloneableVector};
use slice::{Items, MutItems};
/// An owned, growable vector.
@ -387,6 +386,11 @@ impl<T: PartialOrd> PartialOrd for Vec<T> {
impl<T: Eq> Eq for Vec<T> {}
impl<T: PartialEq, V: Vector<T>> Equiv<V> for Vec<T> {
#[inline]
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
}
impl<T: Ord> Ord for Vec<T> {
#[inline]
fn cmp(&self, other: &Vec<T>) -> Ordering {
@ -401,6 +405,11 @@ impl<T> Collection for Vec<T> {
}
}
impl<T: Clone> CloneableVector<T> for Vec<T> {
fn to_owned(&self) -> Vec<T> { self.clone() }
fn into_owned(self) -> Vec<T> { self }
}
// FIXME: #13996: need a way to mark the return value as `noalias`
#[inline(never)]
unsafe fn alloc_or_realloc<T>(ptr: *mut T, size: uint, old_size: uint) -> *mut T {
@ -1511,52 +1520,6 @@ pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (Vec<T>, Vec<U>) {
(ts, us)
}
/// Mechanism to convert from a `Vec<T>` to a `[T]`.
///
/// In a post-DST world this will be used to convert to any `Ptr<[T]>`.
///
/// This could be implemented on more types than just pointers to vectors, but
/// the recommended approach for those types is to implement `FromIterator`.
// FIXME(#12938): Update doc comment when DST lands
pub trait FromVec<T> {
/// Convert a `Vec<T>` into the receiver type.
fn from_vec(v: Vec<T>) -> Self;
}
impl<T> FromVec<T> for ~[T] {
fn from_vec(mut v: Vec<T>) -> ~[T] {
let len = v.len();
let data_size = len.checked_mul(&mem::size_of::<T>());
let data_size = data_size.expect("overflow in from_vec()");
let size = mem::size_of::<RawVec<()>>().checked_add(&data_size);
let size = size.expect("overflow in from_vec()");
// In a post-DST world, we can attempt to reuse the Vec allocation by calling
// shrink_to_fit() on it. That may involve a reallocation+memcpy, but that's no
// different than what we're doing manually here.
let vp = v.as_mut_ptr();
unsafe {
let ret = allocate(size, 8) as *mut RawVec<()>;
let a_size = mem::size_of::<T>();
let a_size = if a_size == 0 {1} else {a_size};
(*ret).fill = len * a_size;
(*ret).alloc = len * a_size;
ptr::copy_nonoverlapping_memory(&mut (*ret).data as *mut _ as *mut u8,
vp as *u8, data_size);
// we've transferred ownership of the contents from v, but we can't drop it
// as it still needs to free its own allocation.
v.set_len(0);
mem::transmute(ret)
}
}
}
/// Unsafe operations
pub mod raw {
use super::Vec;
@ -1580,8 +1543,7 @@ pub mod raw {
mod tests {
use std::prelude::*;
use std::mem::size_of;
use std::kinds::marker;
use super::{unzip, raw, FromVec, Vec};
use super::{unzip, raw, Vec};
#[test]
fn test_small_vec_struct() {
@ -1830,39 +1792,13 @@ mod tests {
assert_eq!(b, vec![1, 2, 3]);
// Test on-heap copy-from-buf.
let c = box [1, 2, 3, 4, 5];
let c = vec![1, 2, 3, 4, 5];
let ptr = c.as_ptr();
let d = raw::from_buf(ptr, 5u);
assert_eq!(d, vec![1, 2, 3, 4, 5]);
}
}
#[test]
fn test_from_vec() {
let a = vec![1u, 2, 3];
let b: ~[uint] = FromVec::from_vec(a);
assert_eq!(b.as_slice(), &[1u, 2, 3]);
let a = vec![];
let b: ~[u8] = FromVec::from_vec(a);
assert_eq!(b.as_slice(), &[]);
let a = vec!["one".to_string(), "two".to_string()];
let b: ~[String] = FromVec::from_vec(a);
assert_eq!(b.as_slice(), &["one".to_string(), "two".to_string()]);
struct Foo {
x: uint,
nocopy: marker::NoCopy
}
let a = vec![Foo{x: 42, nocopy: marker::NoCopy}, Foo{x: 84, nocopy: marker::NoCopy}];
let b: ~[Foo] = FromVec::from_vec(a);
assert_eq!(b.len(), 2);
assert_eq!(b[0].x, 42);
assert_eq!(b[1].x, 84);
}
#[test]
fn test_vec_truncate_drop() {
static mut drops: uint = 0;

View File

@ -159,7 +159,7 @@ mod test {
fn test_fn_a() -> f64 { 1.0 }
fn test_fn_b<T: Empty>(x: T) -> T { x }
fn test_fn_c(_: int, _: f64, _: ~[int], _: int, _: int, _: int) {}
fn test_fn_c(_: int, _: f64, _: int, _: int, _: int) {}
let _ = test_fn_a.clone();
let _ = test_fn_b::<int>.clone();

View File

@ -29,7 +29,7 @@
#![allow(dead_code, missing_doc)]
use fmt;
use intrinsics;
#[cfg(not(test))] use intrinsics;
#[cold] #[inline(never)] // this is the slow path, always
#[lang="fail_"]

View File

@ -828,12 +828,6 @@ impl<'a, T: Show> Show for &'a mut [T] {
}
}
impl<T: Show> Show for ~[T] {
fn fmt(&self, f: &mut Formatter) -> Result {
secret_show(&self.as_slice(), f)
}
}
impl Show for () {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")

View File

@ -100,7 +100,9 @@ pub trait TyVisitor {
fn visit_char(&mut self) -> bool;
#[cfg(stage0)]
fn visit_estr_box(&mut self) -> bool;
#[cfg(stage0)]
fn visit_estr_uniq(&mut self) -> bool;
fn visit_estr_slice(&mut self) -> bool;
fn visit_estr_fixed(&mut self, n: uint, sz: uint, align: uint) -> bool;
@ -110,7 +112,9 @@ pub trait TyVisitor {
fn visit_ptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
#[cfg(stage0)]
fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
#[cfg(stage0)]
fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool;
fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint,

View File

@ -35,7 +35,7 @@ into a `loop`, for example, the `for` loop in this example is essentially
translated to the `loop` below.
```rust
let values = ~[1, 2, 3];
let values = vec![1, 2, 3];
// "Syntactical sugar" taking advantage of an iterator
for &x in values.iter() {
@ -378,7 +378,7 @@ pub trait Iterator<A> {
/// }
/// sum
/// }
/// let x = ~[1,2,3,7,8,9];
/// let x = vec![1,2,3,7,8,9];
/// assert_eq!(process(x.move_iter()), 1006);
/// ```
#[inline]
@ -2425,7 +2425,7 @@ mod tests {
#[test]
fn test_iterator_peekable() {
let xs = box [0u, 1, 2, 3, 4, 5];
let xs = vec![0u, 1, 2, 3, 4, 5];
let mut it = xs.iter().map(|&x|x).peekable();
assert_eq!(it.peek().unwrap(), &0);
assert_eq!(it.next().unwrap(), 0);
@ -2809,7 +2809,7 @@ mod tests {
#[test]
fn test_double_ended_chain() {
let xs = [1, 2, 3, 4, 5];
let ys = box [7, 9, 11];
let ys = [7, 9, 11];
let mut it = xs.iter().chain(ys.iter()).rev();
assert_eq!(it.next().unwrap(), &11)
assert_eq!(it.next().unwrap(), &9)
@ -2826,7 +2826,7 @@ mod tests {
fn test_rposition() {
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
let v = box [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert_eq!(v.iter().rposition(f), Some(3u));
assert!(v.iter().rposition(g).is_none());
@ -2887,7 +2887,7 @@ mod tests {
#[test]
fn test_random_access_chain() {
let xs = [1, 2, 3, 4, 5];
let ys = box [7, 9, 11];
let ys = [7, 9, 11];
let mut it = xs.iter().chain(ys.iter());
assert_eq!(it.idx(0).unwrap(), &1);
assert_eq!(it.idx(5).unwrap(), &7);
@ -3131,7 +3131,7 @@ mod tests {
}
#[test]
fn test_MinMaxResult() {
fn test_min_max_result() {
let r: MinMaxResult<int> = NoElements;
assert_eq!(r.into_option(), None)

View File

@ -130,11 +130,6 @@ pub mod str;
pub mod tuple;
pub mod fmt;
// FIXME: this module should not exist. Once owned allocations are no longer a
// language type, this module can move outside to the owned allocation
// crate.
mod should_not_exist;
#[doc(hidden)]
mod core {
pub use failure;

View File

@ -660,7 +660,7 @@ mod tests {
}
}
fn R(i: Rc<RefCell<int>>) -> R {
fn r(i: Rc<RefCell<int>>) -> R {
R {
i: i
}
@ -673,7 +673,7 @@ mod tests {
let i = Rc::new(RefCell::new(0));
{
let x = R(realclone(&i));
let x = r(realclone(&i));
let opt = Some(x);
let _y = opt.unwrap();
}

View File

@ -503,7 +503,8 @@ impl<T> PartialOrd for *mut T {
}
#[cfg(test)]
pub mod ptr_tests {
#[allow(deprecated, experimental)]
pub mod test {
use super::*;
use prelude::*;
@ -512,6 +513,8 @@ pub mod ptr_tests {
use libc;
use realstd::str;
use realstd::str::Str;
use realstd::vec::Vec;
use realstd::collections::Collection;
use slice::{ImmutableVector, MutableVector};
#[test]
@ -534,20 +537,24 @@ pub mod ptr_tests {
assert_eq!(p.fst, 50);
assert_eq!(p.snd, 60);
let v0 = box [32000u16, 32001u16, 32002u16];
let mut v1 = box [0u16, 0u16, 0u16];
let v0 = vec![32000u16, 32001u16, 32002u16];
let mut v1 = vec![0u16, 0u16, 0u16];
copy_memory(v1.as_mut_ptr().offset(1),
v0.as_ptr().offset(1), 1);
assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
assert!((*v1.get(0) == 0u16 &&
*v1.get(1) == 32001u16 &&
*v1.get(2) == 0u16));
copy_memory(v1.as_mut_ptr(),
v0.as_ptr().offset(2), 1);
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
v1[2] == 0u16));
assert!((*v1.get(0) == 32002u16 &&
*v1.get(1) == 32001u16 &&
*v1.get(2) == 0u16));
copy_memory(v1.as_mut_ptr().offset(2),
v0.as_ptr(), 1u);
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
v1[2] == 32000u16));
assert!((*v1.get(0) == 32002u16 &&
*v1.get(1) == 32001u16 &&
*v1.get(2) == 32000u16));
}
}
@ -569,7 +576,7 @@ pub mod ptr_tests {
"hello".with_c_str(|p0| {
"there".with_c_str(|p1| {
"thing".with_c_str(|p2| {
let v = box [p0, p1, p2, null()];
let v = vec![p0, p1, p2, null()];
unsafe {
assert_eq!(buf_len(v.as_ptr()), 3u);
}
@ -617,7 +624,7 @@ pub mod ptr_tests {
#[test]
fn test_ptr_addition() {
unsafe {
let xs = box [5, ..16];
let xs = Vec::from_elem(16, 5);
let mut ptr = xs.as_ptr();
let end = ptr.offset(16);
@ -626,7 +633,7 @@ pub mod ptr_tests {
ptr = ptr.offset(1);
}
let mut xs_mut = xs.clone();
let mut xs_mut = xs;
let mut m_ptr = xs_mut.as_mut_ptr();
let m_end = m_ptr.offset(16);
@ -635,14 +642,14 @@ pub mod ptr_tests {
m_ptr = m_ptr.offset(1);
}
assert_eq!(xs_mut, box [10, ..16]);
assert!(xs_mut == Vec::from_elem(16, 10));
}
}
#[test]
fn test_ptr_subtraction() {
unsafe {
let xs = box [0,1,2,3,4,5,6,7,8,9];
let xs = vec![0,1,2,3,4,5,6,7,8,9];
let mut idx = 9i8;
let ptr = xs.as_ptr();
@ -651,7 +658,7 @@ pub mod ptr_tests {
idx = idx - 1i8;
}
let mut xs_mut = xs.clone();
let mut xs_mut = xs;
let m_start = xs_mut.as_mut_ptr();
let mut m_ptr = m_start.offset(9);
@ -660,7 +667,7 @@ pub mod ptr_tests {
m_ptr = m_ptr.offset(-1);
}
assert_eq!(xs_mut, box [0,2,4,6,8,10,12,14,16,18]);
assert!(xs_mut == vec![0,2,4,6,8,10,12,14,16,18]);
}
}
@ -670,10 +677,10 @@ pub mod ptr_tests {
let one = "oneOne".to_c_str();
let two = "twoTwo".to_c_str();
let three = "threeThree".to_c_str();
let arr = box [
let arr = vec![
one.with_ref(|buf| buf),
two.with_ref(|buf| buf),
three.with_ref(|buf| buf),
three.with_ref(|buf| buf)
];
let expected_arr = [
one, two, three
@ -700,12 +707,12 @@ pub mod ptr_tests {
let one = "oneOne".to_c_str();
let two = "twoTwo".to_c_str();
let three = "threeThree".to_c_str();
let arr = box [
let arr = vec![
one.with_ref(|buf| buf),
two.with_ref(|buf| buf),
three.with_ref(|buf| buf),
// fake a null terminator
null(),
null()
];
let expected_arr = [
one, two, three

View File

@ -29,16 +29,6 @@ pub struct Box<T> {
pub data: T,
}
/// The representation of a Rust vector
pub struct Vec<T> {
pub fill: uint,
pub alloc: uint,
pub data: T,
}
/// The representation of a Rust string
pub type String = Vec<u8>;
/// The representation of a Rust slice
pub struct Slice<T> {
pub data: *T,
@ -79,7 +69,6 @@ pub trait Repr<T> {
impl<'a, T> Repr<Slice<T>> for &'a [T] {}
impl<'a> Repr<Slice<u8>> for &'a str {}
impl<T> Repr<*Vec<T>> for ~[T] {}
#[cfg(test)]
mod tests {

View File

@ -266,38 +266,19 @@ pub mod traits {
}
}
impl<T:PartialEq> PartialEq for ~[T] {
#[inline]
fn eq(&self, other: &~[T]) -> bool { self.as_slice() == *other }
#[inline]
fn ne(&self, other: &~[T]) -> bool { !self.eq(other) }
}
impl<'a,T:Eq> Eq for &'a [T] {}
impl<T:Eq> Eq for ~[T] {}
impl<'a,T:PartialEq, V: Vector<T>> Equiv<V> for &'a [T] {
#[inline]
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
}
impl<'a,T:PartialEq, V: Vector<T>> Equiv<V> for ~[T] {
#[inline]
fn equiv(&self, other: &V) -> bool { self.as_slice() == other.as_slice() }
}
impl<'a,T:Ord> Ord for &'a [T] {
fn cmp(&self, other: & &'a [T]) -> Ordering {
order::cmp(self.iter(), other.iter())
}
}
impl<T: Ord> Ord for ~[T] {
#[inline]
fn cmp(&self, other: &~[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) }
}
impl<'a, T: PartialOrd> PartialOrd for &'a [T] {
fn lt(&self, other: & &'a [T]) -> bool {
order::lt(self.iter(), other.iter())
@ -315,17 +296,6 @@ pub mod traits {
order::gt(self.iter(), other.iter())
}
}
impl<T: PartialOrd> PartialOrd for ~[T] {
#[inline]
fn lt(&self, other: &~[T]) -> bool { self.as_slice() < other.as_slice() }
#[inline]
fn le(&self, other: &~[T]) -> bool { self.as_slice() <= other.as_slice() }
#[inline]
fn ge(&self, other: &~[T]) -> bool { self.as_slice() >= other.as_slice() }
#[inline]
fn gt(&self, other: &~[T]) -> bool { self.as_slice() > other.as_slice() }
}
}
#[cfg(test)]
@ -342,11 +312,6 @@ impl<'a,T> Vector<T> for &'a [T] {
fn as_slice<'a>(&'a self) -> &'a [T] { *self }
}
impl<T> Vector<T> for ~[T] {
#[inline(always)]
fn as_slice<'a>(&'a self) -> &'a [T] { let v: &'a [T] = *self; v }
}
impl<'a, T> Collection for &'a [T] {
/// Returns the length of a vector
#[inline]
@ -355,14 +320,6 @@ impl<'a, T> Collection for &'a [T] {
}
}
impl<T> Collection for ~[T] {
/// Returns the length of a vector
#[inline]
fn len(&self) -> uint {
self.as_slice().len()
}
}
/// Extension methods for vectors
pub trait ImmutableVector<'a, T> {
/**
@ -927,7 +884,7 @@ pub trait MutableVector<'a, T> {
/// # Example
///
/// ```rust
/// let mut v = ~["foo".to_string(), "bar".to_string(), "baz".to_string()];
/// let mut v = ["foo".to_string(), "bar".to_string(), "baz".to_string()];
///
/// unsafe {
/// // `"baz".to_string()` is deallocated.
@ -1455,7 +1412,3 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunks<'a, T> {
impl<'a, T> Default for &'a [T] {
fn default() -> &'a [T] { &[] }
}
impl<T> Default for ~[T] {
fn default() -> ~[T] { ~[] }
}

View File

@ -192,15 +192,14 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}
#[cfg(stage0)]
fn visit_estr_box(&mut self) -> bool {
true
}
#[cfg(stage0)]
fn visit_estr_uniq(&mut self) -> bool {
self.align_to::<~str>();
if ! self.inner.visit_estr_uniq() { return false; }
self.bump_past::<~str>();
true
false
}
fn visit_estr_slice(&mut self) -> bool {
@ -247,15 +246,14 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}
#[cfg(stage0)]
fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[u8]>();
if ! self.inner.visit_evec_uniq(mtbl, inner) { return false; }
self.bump_past::<~[u8]>();
true
#[cfg(stage0)]
fn visit_evec_uniq(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool {
false
}
fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool {

View File

@ -203,10 +203,6 @@ impl<'a> ReprVisitor<'a> {
true
}
pub fn write_unboxed_vec_repr(&mut self, _: uint, v: &raw::Vec<()>, inner: *TyDesc) -> bool {
self.write_vec_range(&v.data, v.fill, inner)
}
fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool {
try!(self, match ch {
'\t' => self.writer.write("\\t".as_bytes()),
@ -271,15 +267,14 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
})
}
#[cfg(stage0)]
fn visit_estr_box(&mut self) -> bool {
true
false
}
#[cfg(stage0)]
fn visit_estr_uniq(&mut self) -> bool {
self.get::<~str>(|this, s| {
try!(this, this.writer.write(['~' as u8]));
this.write_escaped_slice(*s)
})
false
}
fn visit_estr_slice(&mut self) -> bool {
@ -323,19 +318,14 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
})
}
fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.get::<&raw::Box<raw::Vec<()>>>(|this, b| {
try!(this, this.writer.write(['@' as u8]));
this.write_mut_qualifier(mtbl);
this.write_unboxed_vec_repr(mtbl, &b.data, inner)
})
#[cfg(stage0)]
fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.get::<&raw::Vec<()>>(|this, b| {
try!(this, this.writer.write("box ".as_bytes()));
this.write_unboxed_vec_repr(mtbl, *b, inner)
})
#[cfg(stage0)]
fn visit_evec_uniq(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool {

View File

@ -26,7 +26,6 @@ Simple [DEFLATE][def]-based compression. This is a wrapper around the
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![feature(phase)]
#![deny(deprecated_owned_vector)]
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;
@ -114,7 +113,6 @@ mod tests {
use std::rand::Rng;
#[test]
#[allow(deprecated_owned_vector)]
fn test_flate_round_trip() {
let mut r = rand::task_rng();
let mut words = vec!();

View File

@ -47,7 +47,6 @@ fn main() {
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
#![feature(plugin_registrar, managed_boxes)]
extern crate syntax;

View File

@ -88,7 +88,6 @@
html_playground_url = "http://play.rust-lang.org/")]
#![feature(globs, phase)]
#![deny(missing_doc)]
#![deny(deprecated_owned_vector)]
#[cfg(test)] extern crate debug;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;

View File

@ -31,7 +31,6 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
use std::cell::Cell;
use std::{cmp, os, path};

View File

@ -26,17 +26,13 @@ use std::slice;
// of the contents of `Vec<T>`, since we anticipate that to be a
// frequent way to dynamically construct a vector.
/// MaybeOwnedVector<'a,T> abstracts over `Vec<T>`, `~[T]`, `&'a [T]`.
/// MaybeOwnedVector<'a,T> abstracts over `Vec<T>`, `&'a [T]`.
///
/// Some clients will have a pre-allocated vector ready to hand off in
/// a slice; others will want to create the set on the fly and hand
/// off ownership, via either `Growable` or `FixedLen` depending on
/// which kind of vector they have constructed. (The `FixedLen`
/// variant is provided for interoperability with `std::slice` methods
/// that return `~[T]`.)
/// off ownership, via `Growable`.
pub enum MaybeOwnedVector<'a,T> {
Growable(Vec<T>),
FixedLen(~[T]),
Borrowed(&'a [T]),
}
@ -51,11 +47,6 @@ impl<'a,T> IntoMaybeOwnedVector<'a,T> for Vec<T> {
fn into_maybe_owned(self) -> MaybeOwnedVector<'a,T> { Growable(self) }
}
impl<'a,T> IntoMaybeOwnedVector<'a,T> for ~[T] {
#[inline]
fn into_maybe_owned(self) -> MaybeOwnedVector<'a,T> { FixedLen(self) }
}
impl<'a,T> IntoMaybeOwnedVector<'a,T> for &'a [T] {
#[inline]
fn into_maybe_owned(self) -> MaybeOwnedVector<'a,T> { Borrowed(self) }
@ -65,7 +56,6 @@ impl<'a,T> MaybeOwnedVector<'a,T> {
pub fn iter(&'a self) -> slice::Items<'a,T> {
match self {
&Growable(ref v) => v.iter(),
&FixedLen(ref v) => v.iter(),
&Borrowed(ref v) => v.iter(),
}
}
@ -84,7 +74,6 @@ impl<'b,T> slice::Vector<T> for MaybeOwnedVector<'b,T> {
fn as_slice<'a>(&'a self) -> &'a [T] {
match self {
&Growable(ref v) => v.as_slice(),
&FixedLen(ref v) => v.as_slice(),
&Borrowed(ref v) => v.as_slice(),
}
}
@ -106,15 +95,14 @@ impl<'a,T:fmt::Show> fmt::Show for MaybeOwnedVector<'a,T> {
impl<'a,T:Clone> CloneableVector<T> for MaybeOwnedVector<'a,T> {
/// Returns a copy of `self`.
fn to_owned(&self) -> ~[T] {
fn to_owned(&self) -> Vec<T> {
self.as_slice().to_owned()
}
/// Convert `self` into an owned slice, not making a copy if possible.
fn into_owned(self) -> ~[T] {
fn into_owned(self) -> Vec<T> {
match self {
Growable(v) => v.as_slice().to_owned(),
FixedLen(v) => v,
Borrowed(v) => v.to_owned(),
}
}
@ -125,7 +113,6 @@ impl<'a,T:Clone> MaybeOwnedVector<'a,T> {
pub fn into_vec(self) -> Vec<T> {
match self {
Growable(v) => v,
FixedLen(v) => Vec::from_slice(v.as_slice()),
Borrowed(v) => Vec::from_slice(v),
}
}

View File

@ -191,9 +191,9 @@ type Registers = [uint, ..34];
type Registers = [uint, ..22];
#[cfg(windows, target_arch = "x86_64")]
fn new_regs() -> Box<Registers> { box [0, .. 34] }
fn new_regs() -> Box<Registers> { box() ([0, .. 34]) }
#[cfg(not(windows), target_arch = "x86_64")]
fn new_regs() -> Box<Registers> { box {let v = [0, .. 22]; v} }
fn new_regs() -> Box<Registers> { box() ([0, .. 22]) }
#[cfg(target_arch = "x86_64")]
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,

View File

@ -209,7 +209,6 @@
// NB this does *not* include globs, please keep it that way.
#![feature(macro_rules, phase)]
#![allow(visible_private_types)]
#![deny(deprecated_owned_vector)]
#[cfg(test)] #[phase(plugin, link)] extern crate log;
#[cfg(test)] extern crate rustuv;

View File

@ -43,8 +43,6 @@ fn main() {
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
#![feature(plugin_registrar, managed_boxes)]
extern crate syntax;

View File

@ -115,7 +115,7 @@ if logging is disabled, none of the components of the log will be executed.
html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules)]
#![deny(missing_doc, deprecated_owned_vector)]
#![deny(missing_doc)]
use std::fmt;
use std::io::LineBufferedWriter;

View File

@ -53,8 +53,6 @@
html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
extern crate rand;
pub use bigint::{BigInt, BigUint};

View File

@ -364,7 +364,7 @@
html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, phase)]
#![deny(missing_doc, deprecated_owned_vector)]
#![deny(missing_doc)]
#[cfg(test)]
extern crate stdtest = "test";

View File

@ -37,7 +37,7 @@ pub mod config;
pub fn main_args(args: &[String]) -> int {
let owned_args = args.to_owned();
monitor(proc() run_compiler(owned_args));
monitor(proc() run_compiler(owned_args.as_slice()));
0
}

View File

@ -418,10 +418,10 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
self.walk_expr(&*cond, in_out, loop_scopes);
let mut then_bits = in_out.to_owned();
self.walk_block(&*then, then_bits, loop_scopes);
self.walk_block(&*then, then_bits.as_mut_slice(), loop_scopes);
self.walk_opt_expr(els, in_out, loop_scopes);
join_bits(&self.dfcx.oper, then_bits, in_out);
join_bits(&self.dfcx.oper, then_bits.as_slice(), in_out);
}
ast::ExprWhile(cond, blk) => {
@ -444,8 +444,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
loop_id: expr.id,
break_bits: Vec::from_slice(in_out)
});
self.walk_block(&*blk, body_bits, loop_scopes);
self.add_to_entry_set(expr.id, body_bits);
self.walk_block(&*blk, body_bits.as_mut_slice(), loop_scopes);
self.add_to_entry_set(expr.id, body_bits.as_slice());
let new_loop_scope = loop_scopes.pop().unwrap();
copy_bits(new_loop_scope.break_bits.as_slice(), in_out);
}
@ -468,8 +468,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
loop_id: expr.id,
break_bits: Vec::from_slice(in_out)
});
self.walk_block(&**blk, body_bits, loop_scopes);
self.add_to_entry_set(expr.id, body_bits);
self.walk_block(&**blk, body_bits.as_mut_slice(), loop_scopes);
self.add_to_entry_set(expr.id, body_bits.as_slice());
let new_loop_scope = loop_scopes.pop().unwrap();
assert_eq!(new_loop_scope.loop_id, expr.id);
@ -499,16 +499,17 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
for arm in arms.iter() {
// in_out reflects the discr and all guards to date
self.walk_opt_expr(arm.guard, guards, loop_scopes);
self.walk_opt_expr(arm.guard, guards.as_mut_slice(),
loop_scopes);
// determine the bits for the body and then union
// them into `in_out`, which reflects all bodies to date
let mut body = guards.to_owned();
self.walk_pat_alternatives(arm.pats.as_slice(),
body,
body.as_mut_slice(),
loop_scopes);
self.walk_expr(&*arm.body, body, loop_scopes);
join_bits(&self.dfcx.oper, body, in_out);
self.walk_expr(&*arm.body, body.as_mut_slice(), loop_scopes);
join_bits(&self.dfcx.oper, body.as_slice(), in_out);
}
}
@ -578,7 +579,7 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
self.walk_expr(&**l, in_out, loop_scopes);
let temp = in_out.to_owned();
self.walk_expr(&**r, in_out, loop_scopes);
join_bits(&self.dfcx.oper, temp, in_out);
join_bits(&self.dfcx.oper, temp.as_slice(), in_out);
}
ast::ExprIndex(l, r) |
@ -739,8 +740,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
let initial_state = in_out.to_owned();
for &pat in pats.iter() {
let mut temp = initial_state.clone();
self.walk_pat(pat, temp, loop_scopes);
join_bits(&self.dfcx.oper, temp, in_out);
self.walk_pat(pat, temp.as_mut_slice(), loop_scopes);
join_bits(&self.dfcx.oper, temp.as_slice(), in_out);
}
}

View File

@ -121,8 +121,6 @@ pub enum Lint {
UnusedMustUse,
UnusedResult,
DeprecatedOwnedVector,
Warnings,
RawPointerDeriving,
@ -433,13 +431,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
default: Allow,
}),
("deprecated_owned_vector",
LintSpec {
lint: DeprecatedOwnedVector,
desc: "use of a `~[T]` vector",
default: Allow,
}),
("raw_pointer_deriving",
LintSpec {
lint: RawPointerDeriving,
@ -1229,20 +1220,6 @@ fn check_unused_result(cx: &Context, s: &ast::Stmt) {
}
}
fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) {
let t = ty::expr_ty(cx.tcx, e);
match ty::get(t).sty {
ty::ty_uniq(t) => match ty::get(t).sty {
ty::ty_vec(_, None) => {
cx.span_lint(DeprecatedOwnedVector, e.span,
"use of deprecated `~[]` vector; replaced by `std::vec::Vec`")
}
_ => {}
},
_ => {}
}
}
fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) {
fn is_camel_case(ident: ast::Ident) -> bool {
let ident = token::get_ident(ident);
@ -1855,7 +1832,6 @@ impl<'a> Visitor<()> for Context<'a> {
check_type_limits(self, e);
check_unused_casts(self, e);
check_deprecated_owned_vector(self, e);
visit::walk_expr(self, e, ());
}

View File

@ -24,13 +24,13 @@ modify/read the slot specified by the key.
```rust
local_data_key!(key_int: int)
local_data_key!(key_vector: ~[int])
local_data_key!(key_vector: Vec<int>)
key_int.replace(Some(3));
assert_eq!(*key_int.get().unwrap(), 3);
key_vector.replace(Some(~[4]));
assert_eq!(*key_vector.get().unwrap(), ~[4]);
key_vector.replace(Some(vec![4]));
assert_eq!(*key_vector.get().unwrap(), vec![4]);
```
*/

View File

@ -35,7 +35,6 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![deny(deprecated_owned_vector)]
use std::char;
use std::cmp;

View File

@ -81,7 +81,7 @@ fn main() {
```
Two wrapper functions are provided to encode a Encodable object
into a string (String) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m)`.
into a string (String) or buffer (vec![u8]): `str_encode(&m)` and `buffer_encode(&m)`.
```rust
use serialize::json;
@ -2225,10 +2225,6 @@ impl<'a, A:ToJson> ToJson for &'a [A] {
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
}
impl<A:ToJson> ToJson for ~[A] {
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
}
impl<A:ToJson> ToJson for Vec<A> {
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
}
@ -3048,7 +3044,8 @@ mod tests {
let _hm: HashMap<uint, bool> = Decodable::decode(&mut decoder).unwrap();
}
fn assert_stream_equal(src: &str, expected: ~[(JsonEvent, ~[StackElement])]) {
fn assert_stream_equal(src: &str,
expected: Vec<(JsonEvent, Vec<StackElement>)>) {
let mut parser = Parser::new(src.chars());
let mut i = 0;
loop {
@ -3056,7 +3053,7 @@ mod tests {
Some(e) => e,
None => { break; }
};
let (ref expected_evt, ref expected_stack) = expected[i];
let (ref expected_evt, ref expected_stack) = *expected.get(i);
if !parser.stack().is_equal_to(expected_stack.as_slice()) {
fail!("Parser stack is not equal to {}", expected_stack);
}
@ -3065,26 +3062,27 @@ mod tests {
}
}
#[test]
#[ignore(cfg(target_word_size = "32"))] // FIXME(#14064)
fn test_streaming_parser() {
assert_stream_equal(
r#"{ "foo":"bar", "array" : [0, 1, 2,3 ,4,5], "idents":[null,true,false]}"#,
~[
(ObjectStart, ~[]),
(StringValue("bar".to_string()), ~[Key("foo")]),
(ListStart, ~[Key("array")]),
(NumberValue(0.0), ~[Key("array"), Index(0)]),
(NumberValue(1.0), ~[Key("array"), Index(1)]),
(NumberValue(2.0), ~[Key("array"), Index(2)]),
(NumberValue(3.0), ~[Key("array"), Index(3)]),
(NumberValue(4.0), ~[Key("array"), Index(4)]),
(NumberValue(5.0), ~[Key("array"), Index(5)]),
(ListEnd, ~[Key("array")]),
(ListStart, ~[Key("idents")]),
(NullValue, ~[Key("idents"), Index(0)]),
(BooleanValue(true), ~[Key("idents"), Index(1)]),
(BooleanValue(false), ~[Key("idents"), Index(2)]),
(ListEnd, ~[Key("idents")]),
(ObjectEnd, ~[]),
vec![
(ObjectStart, vec![]),
(StringValue("bar".to_string()), vec![Key("foo")]),
(ListStart, vec![Key("array")]),
(NumberValue(0.0), vec![Key("array"), Index(0)]),
(NumberValue(1.0), vec![Key("array"), Index(1)]),
(NumberValue(2.0), vec![Key("array"), Index(2)]),
(NumberValue(3.0), vec![Key("array"), Index(3)]),
(NumberValue(4.0), vec![Key("array"), Index(4)]),
(NumberValue(5.0), vec![Key("array"), Index(5)]),
(ListEnd, vec![Key("array")]),
(ListStart, vec![Key("idents")]),
(NullValue, vec![Key("idents"), Index(0)]),
(BooleanValue(true), vec![Key("idents"), Index(1)]),
(BooleanValue(false), vec![Key("idents"), Index(2)]),
(ListEnd, vec![Key("idents")]),
(ObjectEnd, vec![]),
]
);
}
@ -3115,34 +3113,34 @@ mod tests {
assert_stream_equal(
"{}",
box [(ObjectStart, box []), (ObjectEnd, box [])]
vec![(ObjectStart, vec![]), (ObjectEnd, vec![])]
);
assert_stream_equal(
"{\"a\": 3}",
box [
(ObjectStart, box []),
(NumberValue(3.0), box [Key("a")]),
(ObjectEnd, box []),
vec![
(ObjectStart, vec![]),
(NumberValue(3.0), vec![Key("a")]),
(ObjectEnd, vec![]),
]
);
assert_stream_equal(
"{ \"a\": null, \"b\" : true }",
box [
(ObjectStart, box []),
(NullValue, box [Key("a")]),
(BooleanValue(true), box [Key("b")]),
(ObjectEnd, box []),
vec![
(ObjectStart, vec![]),
(NullValue, vec![Key("a")]),
(BooleanValue(true), vec![Key("b")]),
(ObjectEnd, vec![]),
]
);
assert_stream_equal(
"{\"a\" : 1.0 ,\"b\": [ true ]}",
box [
(ObjectStart, box []),
(NumberValue(1.0), box [Key("a")]),
(ListStart, box [Key("b")]),
(BooleanValue(true),box [Key("b"), Index(0)]),
(ListEnd, box [Key("b")]),
(ObjectEnd, box []),
vec![
(ObjectStart, vec![]),
(NumberValue(1.0), vec![Key("a")]),
(ListStart, vec![Key("b")]),
(BooleanValue(true),vec![Key("b"), Index(0)]),
(ListEnd, vec![Key("b")]),
(ObjectEnd, vec![]),
]
);
assert_stream_equal(
@ -3154,19 +3152,19 @@ mod tests {
{ "c": {"d": null} }
]
}"#,
~[
(ObjectStart, ~[]),
(NumberValue(1.0), ~[Key("a")]),
(ListStart, ~[Key("b")]),
(BooleanValue(true), ~[Key("b"), Index(0)]),
(StringValue("foo\nbar".to_string()), ~[Key("b"), Index(1)]),
(ObjectStart, ~[Key("b"), Index(2)]),
(ObjectStart, ~[Key("b"), Index(2), Key("c")]),
(NullValue, ~[Key("b"), Index(2), Key("c"), Key("d")]),
(ObjectEnd, ~[Key("b"), Index(2), Key("c")]),
(ObjectEnd, ~[Key("b"), Index(2)]),
(ListEnd, ~[Key("b")]),
(ObjectEnd, ~[]),
vec![
(ObjectStart, vec![]),
(NumberValue(1.0), vec![Key("a")]),
(ListStart, vec![Key("b")]),
(BooleanValue(true), vec![Key("b"), Index(0)]),
(StringValue("foo\nbar".to_string()), vec![Key("b"), Index(1)]),
(ObjectStart, vec![Key("b"), Index(2)]),
(ObjectStart, vec![Key("b"), Index(2), Key("c")]),
(NullValue, vec![Key("b"), Index(2), Key("c"), Key("d")]),
(ObjectEnd, vec![Key("b"), Index(2), Key("c")]),
(ObjectEnd, vec![Key("b"), Index(2)]),
(ListEnd, vec![Key("b")]),
(ObjectEnd, vec![]),
]
);
}
@ -3175,70 +3173,70 @@ mod tests {
fn test_read_list_streaming() {
assert_stream_equal(
"[]",
box [
(ListStart, box []),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"[ ]",
box [
(ListStart, box []),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"[true]",
box [
(ListStart, box []),
(BooleanValue(true), box [Index(0)]),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(BooleanValue(true), vec![Index(0)]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"[ false ]",
box [
(ListStart, box []),
(BooleanValue(false), box [Index(0)]),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(BooleanValue(false), vec![Index(0)]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"[null]",
box [
(ListStart, box []),
(NullValue, box [Index(0)]),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(NullValue, vec![Index(0)]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"[3, 1]",
box [
(ListStart, box []),
(NumberValue(3.0), box [Index(0)]),
(NumberValue(1.0), box [Index(1)]),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(NumberValue(3.0), vec![Index(0)]),
(NumberValue(1.0), vec![Index(1)]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"\n[3, 2]\n",
box [
(ListStart, box []),
(NumberValue(3.0), box [Index(0)]),
(NumberValue(2.0), box [Index(1)]),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(NumberValue(3.0), vec![Index(0)]),
(NumberValue(2.0), vec![Index(1)]),
(ListEnd, vec![]),
]
);
assert_stream_equal(
"[2, [4, 1]]",
box [
(ListStart, box []),
(NumberValue(2.0), box [Index(0)]),
(ListStart, box [Index(1)]),
(NumberValue(4.0), box [Index(1), Index(0)]),
(NumberValue(1.0), box [Index(1), Index(1)]),
(ListEnd, box [Index(1)]),
(ListEnd, box []),
vec![
(ListStart, vec![]),
(NumberValue(2.0), vec![Index(0)]),
(ListStart, vec![Index(1)]),
(NumberValue(4.0), vec![Index(1), Index(0)]),
(NumberValue(1.0), vec![Index(1), Index(1)]),
(ListEnd, vec![Index(1)]),
(ListEnd, vec![]),
]
);
@ -3368,7 +3366,7 @@ mod tests {
assert_eq!((1, 2, 3).to_json(), list3);
assert_eq!([1, 2].to_json(), list2);
assert_eq!((&[1, 2, 3]).to_json(), list3);
assert_eq!((~[1, 2]).to_json(), list2);
assert_eq!((vec![1, 2]).to_json(), list2);
assert_eq!(vec!(1, 2, 3).to_json(), list3);
let mut tree_map = TreeMap::new();
tree_map.insert("a".to_string(), 1);

View File

@ -425,32 +425,6 @@ impl<'a, E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for &'a [T] {
}
}
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for ~[T] {
fn encode(&self, s: &mut S) -> Result<(), E> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
try!(s.emit_seq_elt(i, |s| e.encode(s)))
}
Ok(())
})
}
}
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for ~[T] {
fn decode(d: &mut D) -> Result<~[T], E> {
use std::vec::FromVec;
d.read_seq(|d, len| {
let mut v: Vec<T> = Vec::with_capacity(len);
for i in range(0, len) {
v.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
}
let k: ~[T] = FromVec::from_vec(v);
Ok(k)
})
}
}
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for Vec<T> {
fn encode(&self, s: &mut S) -> Result<(), E> {
s.emit_seq(self.len(), |s| {

View File

@ -278,18 +278,6 @@ pub trait OwnedAsciiCast {
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii>;
}
impl OwnedAsciiCast for ~[u8] {
#[inline]
fn is_ascii(&self) -> bool {
self.as_slice().is_ascii()
}
#[inline]
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
mem::transmute(Vec::from_slice(self.as_slice()))
}
}
impl OwnedAsciiCast for String {
#[inline]
fn is_ascii(&self) -> bool {
@ -353,14 +341,6 @@ impl<'a> AsciiStr for &'a [Ascii] {
}
}
impl IntoStr for ~[Ascii] {
#[inline]
fn into_str(self) -> String {
let vector: Vec<Ascii> = self.as_slice().iter().map(|x| *x).collect();
vector.into_str()
}
}
impl IntoStr for Vec<Ascii> {
#[inline]
fn into_str(self) -> String {
@ -592,8 +572,8 @@ mod tests {
let test = &[40u8, 32u8, 59u8];
assert_eq!(test.to_ascii(), v2ascii!([40, 32, 59]));
assert_eq!("( ;".to_ascii(), v2ascii!([40, 32, 59]));
let v = box [40u8, 32u8, 59u8];
assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
let v = vec![40u8, 32u8, 59u8];
assert_eq!(v.as_slice().to_ascii(), v2ascii!([40, 32, 59]));
assert_eq!("( ;".to_string().as_slice().to_ascii(), v2ascii!([40, 32, 59]));
assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), "abcdef&?#".to_string());
@ -623,7 +603,7 @@ mod tests {
#[test]
fn test_owned_ascii_vec() {
assert_eq!(("( ;".to_string()).into_ascii(), vec2ascii![40, 32, 59]);
assert_eq!((box [40u8, 32u8, 59u8]).into_ascii(), vec2ascii![40, 32, 59]);
assert_eq!((vec![40u8, 32u8, 59u8]).into_ascii(), vec2ascii![40, 32, 59]);
}
#[test]

View File

@ -15,9 +15,9 @@ use comm::{Sender, Receiver};
use io;
use option::{None, Option, Some};
use result::{Ok, Err};
use super::{Reader, Writer, IoResult};
use str::StrSlice;
use slice::{bytes, MutableVector, ImmutableVector};
use str::StrSlice;
use super::{Reader, Writer, IoResult};
use vec::Vec;
/// Allows reading from a rx.
@ -162,14 +162,14 @@ mod test {
assert_eq!(Ok(2), reader.read(buf));
assert_eq!(&[7,8,6], buf.as_slice());
match reader.read(buf) {
match reader.read(buf.as_mut_slice()) {
Ok(..) => fail!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile),
}
assert_eq!(&[7,8,6], buf.as_slice());
// Ensure it continues to fail in the same way.
match reader.read(buf) {
match reader.read(buf.as_mut_slice()) {
Ok(..) => fail!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile),
}

View File

@ -447,10 +447,10 @@ mod test {
#[test]
fn test_read_f32() {
//big-endian floating-point 8.1250
let buf = box [0x41, 0x02, 0x00, 0x00];
let buf = vec![0x41, 0x02, 0x00, 0x00];
let mut writer = MemWriter::new();
writer.write(buf).unwrap();
writer.write(buf.as_slice()).unwrap();
let mut reader = MemReader::new(writer.unwrap());
let f = reader.read_be_f32().unwrap();

View File

@ -52,6 +52,9 @@ fs::unlink(&path);
use c_str::ToCStr;
use clone::Clone;
use collections::Collection;
use io::{FilePermission, Write, UnstableFileStat, Open, FileAccess, FileMode};
use io::{IoResult, IoError, FileStat, SeekStyle, Seek, Writer, Reader};
use io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append};
use io;
use iter::Iterator;
use kinds::Send;
@ -60,14 +63,10 @@ use option::{Some, None, Option};
use owned::Box;
use path::{Path, GenericPath};
use path;
use result::{Ok, Err};
use rt::rtio::{RtioFileStream, IoFactory, LocalIo};
use result::{Err, Ok};
use rt::rtio::LocalIo;
use rt::rtio;
use slice::{OwnedVector, ImmutableVector};
use super::UnstableFileStat;
use super::{FileMode, FileAccess, FileStat, IoResult, FilePermission};
use super::{Reader, Writer, Seek, Append, SeekCur, SeekEnd, SeekSet};
use super::{SeekStyle, Read, Write, ReadWrite, Open, IoError, Truncate};
use slice::ImmutableVector;
use vec::Vec;
/// Unconstrained file access type that exposes read and write operations
@ -82,7 +81,7 @@ use vec::Vec;
/// configured at creation time, via the `FileAccess` parameter to
/// `File::open_mode()`.
pub struct File {
fd: Box<RtioFileStream:Send>,
fd: Box<rtio::RtioFileStream:Send>,
path: Path,
last_nread: int,
}
@ -846,7 +845,7 @@ mod test {
let mut read_buf = [0, .. 1028];
let read_str = match check!(read_stream.read(read_buf)) {
-1|0 => fail!("shouldn't happen"),
n => str::from_utf8(read_buf.slice_to(n).to_owned()).unwrap().to_owned()
n => str::from_utf8(read_buf.slice_to(n)).unwrap().to_owned()
};
assert_eq!(read_str, message.to_owned());
}

View File

@ -450,8 +450,8 @@ mod test {
#[test]
fn test_buf_reader() {
let in_buf = box [0, 1, 2, 3, 4, 5, 6, 7];
let mut reader = BufReader::new(in_buf);
let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
let mut reader = BufReader::new(in_buf.as_slice());
let mut buf = [];
assert_eq!(reader.read(buf), Ok(0));
assert_eq!(reader.tell(), Ok(0));
@ -466,7 +466,7 @@ mod test {
assert_eq!(reader.read(buf), Ok(3));
assert_eq!(buf.slice(0, 3), &[5, 6, 7]);
assert!(reader.read(buf).is_err());
let mut reader = BufReader::new(in_buf);
let mut reader = BufReader::new(in_buf.as_slice());
assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3));
assert_eq!(reader.read_until(3).unwrap(), vec!(4, 5, 6, 7));
assert!(reader.read(buf).is_err());

View File

@ -856,8 +856,8 @@ mod tests {
})
iotest!(fn test_add_to_env() {
let new_env = box [("RUN_TEST_NEW_ENV", "123")];
let prog = env_cmd().env(new_env).spawn().unwrap();
let new_env = vec![("RUN_TEST_NEW_ENV", "123")];
let prog = env_cmd().env(new_env.as_slice()).spawn().unwrap();
let result = prog.wait_with_output().unwrap();
let output = str::from_utf8_lossy(result.output.as_slice()).into_string();

View File

@ -300,24 +300,24 @@ mod test {
#[test]
fn test_null_writer() {
let mut s = NullWriter;
let buf = box [0, 0, 0];
s.write(buf).unwrap();
let buf = vec![0, 0, 0];
s.write(buf.as_slice()).unwrap();
s.flush().unwrap();
}
#[test]
fn test_zero_reader() {
let mut s = ZeroReader;
let mut buf = box [1, 2, 3];
assert_eq!(s.read(buf), Ok(3));
assert_eq!(box [0, 0, 0], buf);
let mut buf = vec![1, 2, 3];
assert_eq!(s.read(buf.as_mut_slice()), Ok(3));
assert_eq!(vec![0, 0, 0], buf);
}
#[test]
fn test_null_reader() {
let mut r = NullReader;
let mut buf = box [0];
assert!(r.read(buf).is_err());
let mut buf = vec![0];
assert!(r.read(buf.as_mut_slice()).is_err());
}
#[test]

View File

@ -42,7 +42,7 @@ use path::{Path, GenericPath, BytesContainer};
use ptr::RawPtr;
use ptr;
use result::{Err, Ok, Result};
use slice::{Vector, ImmutableVector, MutableVector, OwnedVector};
use slice::{Vector, ImmutableVector, MutableVector};
use str::{Str, StrSlice, StrAllocating};
use str;
use string::String;
@ -536,7 +536,7 @@ pub fn self_exe_name() -> Option<Path> {
unsafe {
use libc::funcs::bsd44::*;
use libc::consts::os::extra::*;
let mib = box [CTL_KERN as c_int,
let mib = vec![CTL_KERN as c_int,
KERN_PROC as c_int,
KERN_PROC_PATHNAME as c_int, -1 as c_int];
let mut sz: libc::size_t = 0;

View File

@ -63,8 +63,6 @@ println!("path exists: {}", path.exists());
*/
#![deny(deprecated_owned_vector)]
use collections::Collection;
use c_str::CString;
use clone::Clone;
@ -527,13 +525,6 @@ impl<'a> BytesContainer for &'a [u8] {
}
}
impl BytesContainer for ~[u8] {
#[inline]
fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
self.as_slice()
}
}
impl BytesContainer for Vec<u8> {
#[inline]
fn container_as_bytes<'a>(&'a self) -> &'a [u8] {

View File

@ -22,7 +22,7 @@ use option::{Option, None, Some};
use str::Str;
use str;
use slice::{CloneableVector, Splits, Vector, VectorVector,
ImmutableEqVector, OwnedVector, ImmutableVector};
ImmutableEqVector, ImmutableVector};
use vec::Vec;
use super::{BytesContainer, GenericPath, GenericPathUnsafe};
@ -282,7 +282,6 @@ impl GenericPath for Path {
}
}
#[allow(deprecated_owned_vector)]
fn path_relative_from(&self, base: &Path) -> Option<Path> {
if self.is_absolute() != base.is_absolute() {
if self.is_absolute() {

View File

@ -21,7 +21,7 @@ use io::Writer;
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map};
use mem;
use option::{Option, Some, None};
use slice::{Vector, OwnedVector, ImmutableVector};
use slice::{Vector, ImmutableVector};
use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice};
use string::String;
use vec::Vec;

View File

@ -83,7 +83,7 @@
#[doc(no_inline)] pub use slice::{MutableCloneableVector, MutableOrdVector};
#[doc(no_inline)] pub use slice::{ImmutableVector, MutableVector};
#[doc(no_inline)] pub use slice::{ImmutableEqVector, ImmutableOrdVector};
#[doc(no_inline)] pub use slice::{Vector, VectorVector, OwnedVector};
#[doc(no_inline)] pub use slice::{Vector, VectorVector};
#[doc(no_inline)] pub use slice::MutableVectorAllocating;
#[doc(no_inline)] pub use string::String;
#[doc(no_inline)] pub use vec::Vec;

View File

@ -71,7 +71,6 @@ impl<R: Reader> Rng for ReaderRng<R> {
}
#[cfg(test)]
#[allow(deprecated_owned_vector)]
mod test {
use prelude::*;
@ -83,24 +82,23 @@ mod test {
#[test]
fn test_reader_rng_u64() {
// transmute from the target to avoid endianness concerns.
let v = box [1u64, 2u64, 3u64];
let bytes: ~[u8] = unsafe {mem::transmute(v)};
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
let v = vec![0u8, 0, 0, 0, 0, 0, 0, 1,
0 , 0, 0, 0, 0, 0, 0, 2,
0, 0, 0, 0, 0, 0, 0, 3];
let mut rng = ReaderRng::new(MemReader::new(v));
assert_eq!(rng.next_u64(), 1);
assert_eq!(rng.next_u64(), 2);
assert_eq!(rng.next_u64(), 3);
assert_eq!(rng.next_u64(), mem::to_be64(1));
assert_eq!(rng.next_u64(), mem::to_be64(2));
assert_eq!(rng.next_u64(), mem::to_be64(3));
}
#[test]
fn test_reader_rng_u32() {
// transmute from the target to avoid endianness concerns.
let v = box [1u32, 2u32, 3u32];
let bytes: ~[u8] = unsafe {mem::transmute(v)};
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3];
let mut rng = ReaderRng::new(MemReader::new(v));
assert_eq!(rng.next_u32(), 1);
assert_eq!(rng.next_u32(), 2);
assert_eq!(rng.next_u32(), 3);
assert_eq!(rng.next_u32(), mem::to_be32(1));
assert_eq!(rng.next_u32(), mem::to_be32(2));
assert_eq!(rng.next_u32(), mem::to_be32(3));
}
#[test]
fn test_reader_rng_fill_bytes() {

View File

@ -37,8 +37,8 @@ impl<T: fmt::Show> ToStr for T {
#[cfg(test)]
mod tests {
use prelude::*;
use super::*;
use str::StrAllocating;
#[test]
fn test_simple_types() {
@ -54,11 +54,11 @@ mod tests {
#[test]
fn test_vectors() {
let x: ~[int] = box [];
let x: Vec<int> = vec![];
assert_eq!(x.to_str(), "[]".to_string());
assert_eq!((box [1]).to_str(), "[1]".to_string());
assert_eq!((box [1, 2, 3]).to_str(), "[1, 2, 3]".to_string());
assert!((box [box [], box [1], box [1, 1]]).to_str() ==
assert_eq!((vec![1]).to_str(), "[1]".to_string());
assert_eq!((vec![1, 2, 3]).to_str(), "[1, 2, 3]".to_string());
assert!((vec![vec![], vec![1], vec![1, 1]]).to_str() ==
"[[], [1], [1, 1]]".to_string());
}
}

View File

@ -26,7 +26,7 @@
html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(phase, globs, macro_rules)]
#![deny(deprecated_owned_vector)]
#![deny(missing_doc)]
#![no_std]

View File

@ -30,6 +30,7 @@ pub enum ObsoleteSyntax {
ObsoleteOwnedType,
ObsoleteOwnedExpr,
ObsoleteOwnedPattern,
ObsoleteOwnedVector,
}
pub trait ParserObsoleteMethods {
@ -63,6 +64,10 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
"`~` notation for owned pointer patterns",
"use the `box` operator instead of `~`"
),
ObsoleteOwnedVector => (
"`~[T]` is no longer a type",
"use the `Vec` type instead"
),
};
self.report(sp, kind, kind_str, desc);

View File

@ -1315,11 +1315,8 @@ impl<'a> Parser<'a> {
// OWNED POINTER
self.bump();
match self.token {
token::IDENT(ref ident, _)
if "str" == token::get_ident(*ident).get() => {
// This is OK (for now).
}
token::LBRACKET => {} // Also OK.
token::LBRACKET =>
self.obsolete(self.last_span, ObsoleteOwnedVector),
_ => self.obsolete(self.last_span, ObsoleteOwnedType),
};
TyUniq(self.parse_ty(false))
@ -2342,7 +2339,10 @@ impl<'a> Parser<'a> {
hi = e.span.hi;
// HACK: turn ~[...] into a ~-vec
ex = match e.node {
ExprVec(..) | ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq),
ExprVec(..) | ExprRepeat(..) => {
self.obsolete(self.last_span, ObsoleteOwnedVector);
ExprVstore(e, ExprVstoreUniq)
}
ExprLit(lit) if lit_is_str(lit) => {
self.obsolete(self.last_span, ObsoleteOwnedExpr);
ExprVstore(e, ExprVstoreUniq)
@ -2375,6 +2375,7 @@ impl<'a> Parser<'a> {
// HACK: turn `box [...]` into a boxed-vec
ex = match subexpression.node {
ExprVec(..) | ExprRepeat(..) => {
self.obsolete(self.last_span, ObsoleteOwnedVector);
ExprVstore(subexpression, ExprVstoreUniq)
}
ExprLit(lit) if lit_is_str(lit) => {

View File

@ -33,7 +33,6 @@
html_root_url = "http://doc.rust-lang.org/")]
#![feature(asm, macro_rules, phase)]
#![deny(deprecated_owned_vector)]
extern crate getopts;
extern crate regex;
@ -72,7 +71,7 @@ pub mod test {
MetricChange, Improvement, Regression, LikelyNoise,
StaticTestFn, StaticTestName, DynTestName, DynTestFn,
run_test, test_main, test_main_static, filter_tests,
parse_opts, StaticBenchFn, test_main_static_x};
parse_opts, StaticBenchFn};
}
pub mod stats;
@ -263,14 +262,6 @@ pub fn test_main_static(args: &[String], tests: &[TestDescAndFn]) {
test_main(args, owned_tests)
}
pub fn test_main_static_x(args: &[~str], tests: &[TestDescAndFn]) {
test_main_static(args.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.as_slice(),
tests)
}
pub enum ColorConfig {
AutoColor,
AlwaysColor,

View File

@ -167,7 +167,6 @@ impl<T: FloatMath + FromPrimitive> Summary<T> {
impl<'a,T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
// FIXME #11059 handle NaN, inf and overflow
#[allow(deprecated_owned_vector)]
fn sum(self) -> T {
let mut partials = vec![];
@ -1027,7 +1026,6 @@ mod tests {
#[test]
fn test_boxplot_nonpositive() {
#[allow(deprecated_owned_vector)]
fn t(s: &Summary<f64>, expected: String) {
use std::io::MemWriter;
let mut m = MemWriter::new();

View File

@ -20,7 +20,6 @@
html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(phase)]
#![deny(deprecated_owned_vector)]
#[cfg(test)] extern crate debug;

View File

@ -75,7 +75,7 @@ fn main() {
let clen = seq.len();
let mut seqlen = Future::spawn(proc() {
let substs = ~[
let substs = vec![
(regex!("B"), "(c|g|t)"),
(regex!("D"), "(a|g|t)"),
(regex!("H"), "(a|c|t)"),
@ -95,7 +95,7 @@ fn main() {
seq.len()
});
let variants = ~[
let variants = vec![
regex!("agggtaaa|tttaccct"),
regex!("[cgt]gggtaaa|tttaccc[acg]"),
regex!("a[act]ggtaaa|tttacc[agt]t"),

View File

@ -9,11 +9,10 @@
// except according to those terms.
fn test() {
let w: ~[int];
let w: &mut [int];
w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w`
//~^ ERROR cannot assign to immutable vec content `w[..]`
let mut w: ~[int];
let mut w: &mut [int];
w[5] = 0; //~ ERROR use of possibly uninitialized variable: `w`
}

View File

@ -11,8 +11,6 @@
#![deny(unreachable_code)]
#![allow(unused_variable)]
#![allow(dead_code)]
#![allow(deprecated_owned_vector)]
fn fail_len(v: Vec<int> ) -> uint {
let mut i = 3;

View File

@ -1,16 +0,0 @@
// Copyright 2014 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.
#![deny(deprecated_owned_vector)]
fn main() {
~[1]; //~ ERROR use of deprecated `~[]`
//~^ ERROR use of deprecated `~[]`
}

View File

@ -11,7 +11,6 @@
#![feature(managed_boxes)]
#![forbid(heap_memory)]
#![allow(dead_code)]
#![allow(deprecated_owned_vector)]
struct Foo {

View File

@ -11,7 +11,6 @@
#![feature(globs)]
#![deny(unused_imports)]
#![allow(dead_code)]
#![allow(deprecated_owned_vector)]
use cal = bar::c::cc;

View File

@ -13,7 +13,6 @@
#![allow(dead_assignment)]
#![allow(unused_variable)]
#![allow(dead_code)]
#![allow(deprecated_owned_vector)]
#![deny(unused_mut)]

View File

@ -12,7 +12,6 @@
#![allow(dead_code)]
#![deny(unused_unsafe)]
#![allow(deprecated_owned_vector)]
mod foo {

View File

@ -13,7 +13,4 @@ pub fn main() {
struct Foo;
assert!(Some(box Foo).is_some());
let xs: ~[()] = ~[];
assert!(Some(xs).is_some());
}

View File

@ -13,7 +13,6 @@
#![feature(macro_rules, managed_boxes)]
#![deny(warnings)]
#![allow(unused_must_use)]
#![allow(deprecated_owned_vector)]
extern crate debug;

View File

@ -45,7 +45,7 @@ pub fn main() {
p.borrow_mut().y += 3;
assert_eq!(*p.borrow(), Point {x: 3, y: 5});
let v = Rc::new(RefCell::new(~[1, 2, 3]));
let v = Rc::new(RefCell::new([1, 2, 3]));
v.borrow_mut()[0] = 3;
v.borrow_mut()[1] += 3;
assert_eq!((v.borrow()[0], v.borrow()[1], v.borrow()[2]), (3, 5, 3));

View File

@ -62,8 +62,6 @@ impl TyVisitor for MyVisitor {
fn visit_char(&mut self) -> bool { true }
fn visit_estr_box(&mut self) -> bool { true }
fn visit_estr_uniq(&mut self) -> bool { true }
fn visit_estr_slice(&mut self) -> bool { true }
fn visit_estr_fixed(&mut self,
_sz: uint, _sz2: uint,
@ -74,13 +72,6 @@ impl TyVisitor for MyVisitor {
fn visit_ptr(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
fn visit_rptr(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
fn visit_evec_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool {
self.types.push("[".to_string());
unsafe { visit_tydesc(inner, &mut *self as &mut TyVisitor); }
self.types.push("]".to_string());
true
}
fn visit_evec_slice(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { true }
fn visit_evec_fixed(&mut self, _n: uint, _sz: uint, _align: uint,
_mtbl: uint, _inner: *TyDesc) -> bool { true }