/// mem::forget(v);
///
/// // Overwrite memory with 4, 5, 6
- /// for i in 0..len as int {
+ /// for i in 0..len as isize {
/// ptr::write(p.offset(i), 4 + i);
/// }
///
let end = if mem::size_of::<T>() == 0 {
(ptr as usize + self.len()) as *const T
} else {
- ptr.offset(self.len() as int) as *const T
+ ptr.offset(self.len() as isize) as *const T
};
mem::forget(self);
IntoIter { allocation: ptr, cap: cap, ptr: begin, end: end }
/// # Examples
///
/// ```
- /// let mut v = vec![1u, 2, 3, 4];
+ /// let mut v = vec![1, 2, 3, 4];
/// unsafe {
/// v.set_len(1);
/// }
unsafe { // infallible
// The spot to put the new value
{
- let p = self.as_mut_ptr().offset(index as int);
+ let p = self.as_mut_ptr().offset(index as isize);
// Shift everything over to make space. (Duplicating the
// `index`th element into two consecutive places.)
ptr::copy_memory(p.offset(1), &*p, len - index);
let ret;
{
// the place we are taking from.
- let ptr = self.as_mut_ptr().offset(index as int);
+ let ptr = self.as_mut_ptr().offset(index as isize);
// copy it out, unsafely having a copy of the value on
// the stack and in the vector at the same time.
ret = ptr::read(ptr);
}
unsafe {
- let end = (*self.ptr).offset(self.len as int);
+ let end = (*self.ptr).offset(self.len as isize);
ptr::write(&mut *end, value);
self.len += 1;
}
let end = if mem::size_of::<T>() == 0 {
(*self.ptr as usize + self.len()) as *const T
} else {
- (*self.ptr).offset(self.len() as int) as *const T
+ (*self.ptr).offset(self.len() as isize) as *const T
};
self.set_len(0);
Drain {
// types are passed to the allocator by `Vec`.
assert!(mem::min_align_of::<T>() == mem::min_align_of::<U>());
- // This `as int` cast is safe, because the size of the elements of the
+ // This `as isize` cast is safe, because the size of the elements of the
// vector is not 0, and:
//
// 1) If the size of the elements in the vector is 1, the `int` may
//
// 2) If the size of the elements in the vector is >1, the `usize` ->
// `int` conversion can't overflow.
- let offset = vec.len() as int;
+ let offset = vec.len() as isize;
let start = vec.as_mut_ptr();
let mut pv = PartialVecNonZeroSized {
let mut w = 1;
while r < ln {
- let p_r = p.offset(r as int);
- let p_wm1 = p.offset((w - 1) as int);
+ let p_r = p.offset(r as isize);
+ let p_wm1 = p.offset((w - 1) as isize);
if *p_r != *p_wm1 {
if r != w {
let p_w = p_wm1.offset(1);
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> IndexMut<usize> for Vec<T> {
- type Output = T;
-
#[inline]
fn index_mut(&mut self, index: &usize) -> &mut T {
// NB built-in indexing via `&mut [T]`
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::Range<usize>> for Vec<T> {
- type Output = [T];
#[inline]
fn index_mut(&mut self, index: &ops::Range<usize>) -> &mut [T] {
IndexMut::index_mut(&mut **self, index)
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeTo<usize>> for Vec<T> {
- type Output = [T];
#[inline]
fn index_mut(&mut self, index: &ops::RangeTo<usize>) -> &mut [T] {
IndexMut::index_mut(&mut **self, index)
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for Vec<T> {
- type Output = [T];
#[inline]
fn index_mut(&mut self, index: &ops::RangeFrom<usize>) -> &mut [T] {
IndexMut::index_mut(&mut **self, index)
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ops::IndexMut<ops::RangeFull> for Vec<T> {
- type Output = [T];
#[inline]
fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] {
self.as_mut_slice()
self.ptr = mem::transmute(self.ptr as usize + 1);
// Use a non-null pointer value
- Some(ptr::read(mem::transmute(1u)))
+ Some(ptr::read(EMPTY as *mut T))
} else {
let old = self.ptr;
self.ptr = self.ptr.offset(1);
self.end = mem::transmute(self.end as usize - 1);
// Use a non-null pointer value
- Some(ptr::read(mem::transmute(1u)))
+ Some(ptr::read(EMPTY as *mut T))
} else {
self.end = self.end.offset(-1);
self.ptr = mem::transmute(self.ptr as usize + 1);
// Use a non-null pointer value
- Some(ptr::read(mem::transmute(1u)))
+ Some(ptr::read(EMPTY as *mut T))
} else {
let old = self.ptr;
self.ptr = self.ptr.offset(1);
self.end = mem::transmute(self.end as usize - 1);
// Use a non-null pointer value
- Some(ptr::read(mem::transmute(1u)))
+ Some(ptr::read(EMPTY as *mut T))
} else {
self.end = self.end.offset(-1);
#[test]
fn test_partition() {
- assert_eq!(vec![].into_iter().partition(|x: &int| *x < 3), (vec![], vec![]));
- assert_eq!(vec![1, 2, 3].into_iter().partition(|x: &int| *x < 4), (vec![1, 2, 3], vec![]));
- assert_eq!(vec![1, 2, 3].into_iter().partition(|x: &int| *x < 2), (vec![1], vec![2, 3]));
- assert_eq!(vec![1, 2, 3].into_iter().partition(|x: &int| *x < 0), (vec![], vec![1, 2, 3]));
+ assert_eq!(vec![].into_iter().partition(|x: &i32| *x < 3), (vec![], vec![]));
+ assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 4), (vec![1, 2, 3], vec![]));
+ assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 2), (vec![1], vec![2, 3]));
+ assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 0), (vec![], vec![1, 2, 3]));
}
#[test]
#[test]
fn test_vec_truncate_drop() {
static mut drops: u32 = 0;
- struct Elem(int);
+ struct Elem(i32);
impl Drop for Elem {
fn drop(&mut self) {
unsafe { drops += 1; }