diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-01-23 18:15:06 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-01-24 13:52:22 -0800 |
| commit | ad25e208ee4978ca20123bcd2f34c16504518b8d (patch) | |
| tree | 812ad433f7aaf53000f5bb257cb57c0100f518ea /src/libcore/vec.rs | |
| parent | bbbb80559c8e321dc023c48579367e2ef1349b4b (diff) | |
librustc: Allow `&mut` to be loaned; allow `self` to be loaned; make `&mut` loanable to `&`. r=nmatsakis
Diffstat (limited to 'src/libcore/vec.rs')
| -rw-r--r-- | src/libcore/vec.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ee30d7939b7..7d7e16e930c 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -14,6 +14,7 @@ #[forbid(deprecated_pattern)]; #[warn(non_camel_case_types)]; +use cast::transmute; use cast; use cmp::{Eq, Ord}; use iter::BaseIter; @@ -477,14 +478,20 @@ pub fn shift<T>(v: &mut ~[T]) -> T { // Memcopy the head element (the one we want) to the location we just // popped. For the moment it unsafely exists at both the head and last // positions - let first_slice = view(*v, 0, 1); - let last_slice = mut_view(*v, next_ln, ln); - raw::copy_memory(last_slice, first_slice, 1); + { + let first_slice = view(*v, 0, 1); + let last_slice = view(*v, next_ln, ln); + raw::copy_memory(::cast::transmute(last_slice), first_slice, 1); + } // Memcopy everything to the left one element - let init_slice = mut_view(*v, 0, next_ln); - let tail_slice = view(*v, 1, ln); - raw::copy_memory(init_slice, tail_slice, next_ln); + { + let init_slice = view(*v, 0, next_ln); + let tail_slice = view(*v, 1, ln); + raw::copy_memory(::cast::transmute(init_slice), + tail_slice, + next_ln); + } // Set the new length. Now the vector is back to normal raw::set_len(&mut *v, next_ln); |
