Merge remote-tracking branch 'bstrie/rimov' into incoming
Conflicts: src/libsyntax/parse/parser.rs src/test/bench/graph500-bfs.rs src/test/bench/sudoku.rs src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs src/test/run-pass/empty-mutable-vec.rs src/test/run-pass/foreach-nested.rs src/test/run-pass/swap-2.rs
This commit is contained in:
commit
e08a805b30
14
doc/rust.md
14
doc/rust.md
@ -1719,15 +1719,12 @@ vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
|
||||
|
||||
A [_vector_](#vector-types) _expression_ is written by enclosing zero or
|
||||
more comma-separated expressions of uniform type in square brackets.
|
||||
The keyword `mut` can be written after the opening bracket to
|
||||
indicate that the elements of the resulting vector may be mutated.
|
||||
When no mutability is specified, the vector is immutable.
|
||||
|
||||
~~~~
|
||||
[1, 2, 3, 4];
|
||||
["a", "b", "c", "d"];
|
||||
[0, ..128]; // vector with 128 zeros
|
||||
[mut 0u8, 0u8, 0u8, 0u8];
|
||||
[0u8, 0u8, 0u8, 0u8];
|
||||
~~~~
|
||||
|
||||
### Index expressions
|
||||
@ -1749,7 +1746,6 @@ task in a _failing state_.
|
||||
# do task::spawn_unlinked {
|
||||
|
||||
([1, 2, 3, 4])[0];
|
||||
([mut 'x', 'y'])[1] = 'z';
|
||||
(["a", "b"])[10]; // fails
|
||||
|
||||
# }
|
||||
@ -1912,8 +1908,8 @@ No allocation or destruction is entailed.
|
||||
An example of three different swap expressions:
|
||||
|
||||
~~~~~~~~
|
||||
# let mut x = &[mut 0];
|
||||
# let mut a = &[mut 0];
|
||||
# let mut x = &mut [0];
|
||||
# let mut a = &mut [0];
|
||||
# let i = 0;
|
||||
# let y = {mut z: 0};
|
||||
# let b = {mut c: 0};
|
||||
@ -2008,11 +2004,11 @@ the unary copy operator is typically only used to cause an argument to a functio
|
||||
An example of a copy expression:
|
||||
|
||||
~~~~
|
||||
fn mutate(vec: ~[mut int]) {
|
||||
fn mutate(mut vec: ~[int]) {
|
||||
vec[0] = 10;
|
||||
}
|
||||
|
||||
let v = ~[mut 1,2,3];
|
||||
let v = ~[1,2,3];
|
||||
|
||||
mutate(copy v); // Pass a copy
|
||||
|
||||
|
@ -1795,7 +1795,7 @@ Generic `type`, `struct`, and `enum` declarations follow the same pattern:
|
||||
type Set<T> = HashMap<T, ()>;
|
||||
|
||||
struct Stack<T> {
|
||||
elements: ~[mut T]
|
||||
elements: ~[T]
|
||||
}
|
||||
|
||||
enum Option<T> {
|
||||
|
@ -43,7 +43,7 @@ type pointy = {
|
||||
mut g : fn~()->(),
|
||||
|
||||
mut m : ~[maybe_pointy],
|
||||
mut n : ~[mut maybe_pointy],
|
||||
mut n : ~[maybe_pointy],
|
||||
mut o : {x : int, y : maybe_pointy}
|
||||
};
|
||||
// To add: objects; traits; anything type-parameterized?
|
||||
@ -58,7 +58,7 @@ fn empty_pointy() -> @pointy {
|
||||
mut g : fn~()->(){},
|
||||
|
||||
mut m : ~[],
|
||||
mut n : ~[mut],
|
||||
mut n : ~[],
|
||||
mut o : {x : 0, y : none}
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,7 @@ fn nop<T>(_x: T) { }
|
||||
|
||||
fn test_cycles(r : rand::rng, k: uint, n: uint)
|
||||
{
|
||||
let v : ~[mut @pointy] = ~[mut];
|
||||
let mut v : ~[@pointy] = ~[];
|
||||
|
||||
// Create a graph with no edges
|
||||
range(0u, vlen) {|_i|
|
||||
|
@ -25,7 +25,7 @@ fn choice<T: copy>(r : rand::rng, v : ~[T]) -> T {
|
||||
fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u }
|
||||
|
||||
// shuffle a vec in place
|
||||
fn shuffle<T>(r : rand::rng, &v : ~[mut T]) {
|
||||
fn shuffle<T>(r : rand::rng, &v : ~[T]) {
|
||||
let i = vec::len(v);
|
||||
while i >= 2u {
|
||||
// Loop invariant: elements with index >= i have been locked in place.
|
||||
@ -86,7 +86,7 @@ fn main()
|
||||
log(error, choice(r, ~[10, 20, 30]));
|
||||
log(error, if unlikely(r, 5u) { "unlikely" } else { "likely" });
|
||||
|
||||
let a = ~[mut 1, 2, 3];
|
||||
let mut a = ~[1, 2, 3];
|
||||
shuffle(r, a);
|
||||
log(error, a);
|
||||
|
||||
|
@ -156,7 +156,7 @@ fn readclose(fd: libc::c_int) -> ~str {
|
||||
let file = os::fdopen(fd);
|
||||
let reader = io::FILE_reader(file, false);
|
||||
let buf = io::with_bytes_writer(|writer| {
|
||||
let mut bytes = [mut 0, ..4096];
|
||||
let mut bytes = [0, ..4096];
|
||||
while !reader.eof() {
|
||||
let nread = reader.read(bytes, bytes.len());
|
||||
writer.write(bytes.view(0, nread));
|
||||
|
@ -106,10 +106,10 @@ impl SmallBitv {
|
||||
|
||||
struct BigBitv {
|
||||
// only mut b/c of clone and lack of other constructor
|
||||
mut storage: ~[mut uint]
|
||||
mut storage: ~[uint]
|
||||
}
|
||||
|
||||
fn BigBitv(storage: ~[mut uint]) -> BigBitv {
|
||||
fn BigBitv(storage: ~[uint]) -> BigBitv {
|
||||
BigBitv {storage: move storage}
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ pub fn Bitv (nbits: uint, init: bool) -> Bitv {
|
||||
let nelems = nbits/uint_bits +
|
||||
if nbits % uint_bits == 0 {0} else {1};
|
||||
let elem = if init {!0} else {0};
|
||||
let s = cast_to_mut(from_elem(nelems, elem));
|
||||
let s = from_elem(nelems, elem);
|
||||
Big(~BigBitv(move s))
|
||||
};
|
||||
Bitv {rep: move rep, nbits: nbits}
|
||||
@ -518,7 +518,7 @@ impl Bitv: Clone {
|
||||
Bitv{nbits: self.nbits, rep: Small(~SmallBitv{bits: b.bits})}
|
||||
}
|
||||
Big(ref b) => {
|
||||
let st = cast_to_mut(from_elem(self.nbits / uint_bits + 1, 0));
|
||||
let mut st = from_elem(self.nbits / uint_bits + 1, 0);
|
||||
let len = st.len();
|
||||
for uint::range(0, len) |i| { st[i] = b.storage[i]; };
|
||||
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: move st})}
|
||||
|
@ -43,7 +43,7 @@ pub impl BufReader {
|
||||
}
|
||||
|
||||
impl BufReader: Reader {
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
||||
self.as_bytes_reader(|r| r.read(bytes, len) )
|
||||
}
|
||||
fn read_byte(&self) -> int {
|
||||
|
@ -863,7 +863,7 @@ impl TcpSocket {
|
||||
|
||||
/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`
|
||||
impl TcpSocketBuf: io::Reader {
|
||||
fn read(&self, buf: &[mut u8], len: uint) -> uint {
|
||||
fn read(&self, buf: &mut [u8], len: uint) -> uint {
|
||||
if len == 0 { return 0 }
|
||||
let mut count: uint = 0;
|
||||
|
||||
|
@ -66,7 +66,7 @@ pub mod chained {
|
||||
|
||||
struct HashMap_<K, V> {
|
||||
mut count: uint,
|
||||
mut chains: ~[mut Option<@Entry<K,V>>]
|
||||
mut chains: ~[Option<@Entry<K,V>>]
|
||||
}
|
||||
|
||||
pub type T<K, V> = @HashMap_<K, V>;
|
||||
@ -131,7 +131,7 @@ pub mod chained {
|
||||
fn rehash() {
|
||||
let n_old_chains = self.chains.len();
|
||||
let n_new_chains: uint = uint::next_power_of_two(n_old_chains+1u);
|
||||
let new_chains = chains(n_new_chains);
|
||||
let mut new_chains = chains(n_new_chains);
|
||||
for self.each_entry |entry| {
|
||||
let idx = entry.hash % n_new_chains;
|
||||
entry.next = new_chains[idx];
|
||||
@ -369,8 +369,8 @@ pub mod chained {
|
||||
}
|
||||
}
|
||||
|
||||
fn chains<K,V>(nchains: uint) -> ~[mut Option<@Entry<K,V>>] {
|
||||
vec::cast_to_mut(vec::from_elem(nchains, None))
|
||||
fn chains<K,V>(nchains: uint) -> ~[Option<@Entry<K,V>>] {
|
||||
vec::from_elem(nchains, None)
|
||||
}
|
||||
|
||||
pub fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
|
||||
|
@ -788,7 +788,7 @@ pub mod node {
|
||||
* * forest - The forest. This vector is progressively rewritten during
|
||||
* execution and should be discarded as meaningless afterwards.
|
||||
*/
|
||||
pub fn tree_from_forest_destructive(forest: &[mut @Node]) -> @Node {
|
||||
pub fn tree_from_forest_destructive(forest: &mut [@Node]) -> @Node {
|
||||
let mut i;
|
||||
let mut len = vec::len(forest);
|
||||
while len > 1u {
|
||||
@ -1158,18 +1158,17 @@ pub mod node {
|
||||
use core::vec;
|
||||
|
||||
pub struct T {
|
||||
stack: ~[mut @Node],
|
||||
mut stack: ~[@Node],
|
||||
mut stackpos: int,
|
||||
}
|
||||
|
||||
pub fn empty() -> T {
|
||||
let stack : ~[mut @Node] = ~[mut];
|
||||
let mut stack : ~[@Node] = ~[];
|
||||
T { stack: stack, stackpos: -1 }
|
||||
}
|
||||
|
||||
pub fn start(node: @Node) -> T {
|
||||
let stack = vec::cast_to_mut(
|
||||
vec::from_elem(height(node)+1u, node));
|
||||
let stack = vec::from_elem(height(node)+1u, node);
|
||||
T {
|
||||
stack: stack,
|
||||
stackpos: 0,
|
||||
|
@ -64,7 +64,7 @@ pub pure fn merge_sort<T: Copy>(v: &[const T], le: Le<T>) -> ~[T] {
|
||||
}
|
||||
}
|
||||
|
||||
fn part<T: Copy>(arr: &[mut T], left: uint,
|
||||
fn part<T: Copy>(arr: &mut [T], left: uint,
|
||||
right: uint, pivot: uint, compare_func: Le<T>) -> uint {
|
||||
let pivot_value = arr[pivot];
|
||||
arr[pivot] <-> arr[right];
|
||||
@ -81,7 +81,7 @@ fn part<T: Copy>(arr: &[mut T], left: uint,
|
||||
return storage_index;
|
||||
}
|
||||
|
||||
fn qsort<T: Copy>(arr: &[mut T], left: uint,
|
||||
fn qsort<T: Copy>(arr: &mut [T], left: uint,
|
||||
right: uint, compare_func: Le<T>) {
|
||||
if right > left {
|
||||
let pivot = (left + right) / 2u;
|
||||
@ -100,12 +100,12 @@ fn qsort<T: Copy>(arr: &[mut T], left: uint,
|
||||
* Has worst case O(n^2) performance, average case O(n log n).
|
||||
* This is an unstable sort.
|
||||
*/
|
||||
pub fn quick_sort<T: Copy>(arr: &[mut T], compare_func: Le<T>) {
|
||||
pub fn quick_sort<T: Copy>(arr: &mut [T], compare_func: Le<T>) {
|
||||
if len::<T>(arr) == 0u { return; }
|
||||
qsort::<T>(arr, 0u, len::<T>(arr) - 1u, compare_func);
|
||||
}
|
||||
|
||||
fn qsort3<T: Copy Ord Eq>(arr: &[mut T], left: int, right: int) {
|
||||
fn qsort3<T: Copy Ord Eq>(arr: &mut [T], left: int, right: int) {
|
||||
if right <= left { return; }
|
||||
let v: T = arr[right];
|
||||
let mut i: int = left - 1;
|
||||
@ -162,7 +162,7 @@ fn qsort3<T: Copy Ord Eq>(arr: &[mut T], left: int, right: int) {
|
||||
*
|
||||
* This is an unstable sort.
|
||||
*/
|
||||
pub fn quick_sort3<T: Copy Ord Eq>(arr: &[mut T]) {
|
||||
pub fn quick_sort3<T: Copy Ord Eq>(arr: &mut [T]) {
|
||||
if arr.len() <= 1 { return; }
|
||||
qsort3(arr, 0, (arr.len() - 1) as int);
|
||||
}
|
||||
@ -171,7 +171,7 @@ pub trait Sort {
|
||||
fn qsort(self);
|
||||
}
|
||||
|
||||
impl<T: Copy Ord Eq> &[mut T] : Sort {
|
||||
impl<T: Copy Ord Eq> &mut [T] : Sort {
|
||||
fn qsort(self) { quick_sort3(self); }
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ const MIN_MERGE: uint = 64;
|
||||
const MIN_GALLOP: uint = 7;
|
||||
const INITIAL_TMP_STORAGE: uint = 128;
|
||||
|
||||
pub fn tim_sort<T: Copy Ord>(array: &[mut T]) {
|
||||
pub fn tim_sort<T: Copy Ord>(array: &mut [T]) {
|
||||
let size = array.len();
|
||||
if size < 2 {
|
||||
return;
|
||||
@ -218,7 +218,7 @@ pub fn tim_sort<T: Copy Ord>(array: &[mut T]) {
|
||||
ms.merge_force_collapse(array);
|
||||
}
|
||||
|
||||
fn binarysort<T: Copy Ord>(array: &[mut T], start: uint) {
|
||||
fn binarysort<T: Copy Ord>(array: &mut [T], start: uint) {
|
||||
let size = array.len();
|
||||
let mut start = start;
|
||||
assert start <= size;
|
||||
@ -249,7 +249,7 @@ fn binarysort<T: Copy Ord>(array: &[mut T], start: uint) {
|
||||
}
|
||||
|
||||
// Reverse the order of elements in a slice, in place
|
||||
fn reverse_slice<T>(v: &[mut T], start: uint, end:uint) {
|
||||
fn reverse_slice<T>(v: &mut [T], start: uint, end:uint) {
|
||||
let mut i = start;
|
||||
while i < end / 2 {
|
||||
util::swap(&mut v[i], &mut v[end - i - 1]);
|
||||
@ -268,7 +268,7 @@ pure fn min_run_length(n: uint) -> uint {
|
||||
return n + r;
|
||||
}
|
||||
|
||||
fn count_run_ascending<T: Copy Ord>(array: &[mut T]) -> uint {
|
||||
fn count_run_ascending<T: Copy Ord>(array: &mut [T]) -> uint {
|
||||
let size = array.len();
|
||||
assert size > 0;
|
||||
if size == 1 { return 1; }
|
||||
@ -412,7 +412,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
self.runs.push(tmp);
|
||||
}
|
||||
|
||||
fn merge_at(&self, n: uint, array: &[mut T]) {
|
||||
fn merge_at(&self, n: uint, array: &mut [T]) {
|
||||
let mut size = self.runs.len();
|
||||
assert size >= 2;
|
||||
assert n == size-2 || n == size-3;
|
||||
@ -453,7 +453,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
self.runs.pop();
|
||||
}
|
||||
|
||||
fn merge_lo(&self, array: &[mut T], base1: uint, len1: uint,
|
||||
fn merge_lo(&self, array: &mut [T], base1: uint, len1: uint,
|
||||
base2: uint, len2: uint) {
|
||||
assert len1 != 0 && len2 != 0 && base1+len1 == base2;
|
||||
|
||||
@ -556,7 +556,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_hi(&self, array: &[mut T], base1: uint, len1: uint,
|
||||
fn merge_hi(&self, array: &mut [T], base1: uint, len1: uint,
|
||||
base2: uint, len2: uint) {
|
||||
assert len1 != 1 && len2 != 0 && base1 + len1 == base2;
|
||||
|
||||
@ -674,7 +674,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_collapse(&self, array: &[mut T]) {
|
||||
fn merge_collapse(&self, array: &mut [T]) {
|
||||
while self.runs.len() > 1 {
|
||||
let mut n = self.runs.len()-2;
|
||||
let chk = do self.runs.borrow |arr| {
|
||||
@ -692,7 +692,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_force_collapse(&self, array: &[mut T]) {
|
||||
fn merge_force_collapse(&self, array: &mut [T]) {
|
||||
while self.runs.len() > 1 {
|
||||
let mut n = self.runs.len()-2;
|
||||
if n > 0 {
|
||||
@ -708,7 +708,7 @@ impl<T: Copy Ord> MergeState<T> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn copy_vec<T: Copy>(dest: &[mut T], s1: uint,
|
||||
fn copy_vec<T: Copy>(dest: &mut [T], s1: uint,
|
||||
from: &[const T], s2: uint, len: uint) {
|
||||
assert s1+len <= dest.len() && s2+len <= from.len();
|
||||
|
||||
@ -726,7 +726,7 @@ mod test_qsort3 {
|
||||
|
||||
use core::vec;
|
||||
|
||||
pub fn check_sort(v1: &[mut int], v2: &[mut int]) {
|
||||
pub fn check_sort(v1: &mut [int], v2: &mut [int]) {
|
||||
let len = vec::len::<int>(v1);
|
||||
quick_sort3::<int>(v1);
|
||||
let mut i = 0;
|
||||
@ -740,24 +740,24 @@ mod test_qsort3 {
|
||||
#[test]
|
||||
pub fn test() {
|
||||
{
|
||||
let v1 = ~[mut 3, 7, 4, 5, 2, 9, 5, 8];
|
||||
let v2 = ~[mut 2, 3, 4, 5, 5, 7, 8, 9];
|
||||
let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
|
||||
let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{
|
||||
let v1 = ~[mut 1, 1, 1];
|
||||
let v2 = ~[mut 1, 1, 1];
|
||||
let mut v1 = ~[1, 1, 1];
|
||||
let mut v2 = ~[1, 1, 1];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{
|
||||
let v1: ~[mut int] = ~[mut];
|
||||
let v2: ~[mut int] = ~[mut];
|
||||
let mut v1: ~[int] = ~[];
|
||||
let mut v2: ~[int] = ~[];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{ let v1 = ~[mut 9]; let v2 = ~[mut 9]; check_sort(v1, v2); }
|
||||
{ let mut v1 = ~[9]; let mut v2 = ~[9]; check_sort(v1, v2); }
|
||||
{
|
||||
let v1 = ~[mut 9, 3, 3, 3, 9];
|
||||
let v2 = ~[mut 3, 3, 3, 9, 9];
|
||||
let mut v1 = ~[9, 3, 3, 3, 9];
|
||||
let mut v2 = ~[3, 3, 3, 9, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
}
|
||||
@ -772,7 +772,7 @@ mod test_qsort {
|
||||
use core::int;
|
||||
use core::vec;
|
||||
|
||||
pub fn check_sort(v1: &[mut int], v2: &[mut int]) {
|
||||
pub fn check_sort(v1: &mut [int], v2: &mut [int]) {
|
||||
let len = vec::len::<int>(v1);
|
||||
pure fn leual(a: &int, b: &int) -> bool { *a <= *b }
|
||||
quick_sort::<int>(v1, leual);
|
||||
@ -787,24 +787,24 @@ mod test_qsort {
|
||||
#[test]
|
||||
pub fn test() {
|
||||
{
|
||||
let v1 = ~[mut 3, 7, 4, 5, 2, 9, 5, 8];
|
||||
let v2 = ~[mut 2, 3, 4, 5, 5, 7, 8, 9];
|
||||
let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
|
||||
let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{
|
||||
let v1 = ~[mut 1, 1, 1];
|
||||
let v2 = ~[mut 1, 1, 1];
|
||||
let mut v1 = ~[1, 1, 1];
|
||||
let mut v2 = ~[1, 1, 1];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{
|
||||
let v1: ~[mut int] = ~[mut];
|
||||
let v2: ~[mut int] = ~[mut];
|
||||
let mut v1: ~[int] = ~[];
|
||||
let mut v2: ~[int] = ~[];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{ let v1 = ~[mut 9]; let v2 = ~[mut 9]; check_sort(v1, v2); }
|
||||
{ let mut v1 = ~[9]; let mut v2 = ~[9]; check_sort(v1, v2); }
|
||||
{
|
||||
let v1 = ~[mut 9, 3, 3, 3, 9];
|
||||
let v2 = ~[mut 3, 3, 3, 9, 9];
|
||||
let mut v1 = ~[9, 3, 3, 3, 9];
|
||||
let mut v2 = ~[3, 3, 3, 9, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
}
|
||||
@ -812,13 +812,13 @@ mod test_qsort {
|
||||
// Regression test for #750
|
||||
#[test]
|
||||
pub fn test_simple() {
|
||||
let names = ~[mut 2, 1, 3];
|
||||
let mut names = ~[2, 1, 3];
|
||||
|
||||
let expected = ~[1, 2, 3];
|
||||
|
||||
do quick_sort(names) |x, y| { int::le(*x, *y) };
|
||||
|
||||
let immut_names = vec::cast_from_mut(move names);
|
||||
let immut_names = move names;
|
||||
|
||||
let pairs = vec::zip_slice(expected, immut_names);
|
||||
for vec::each(pairs) |p| {
|
||||
@ -870,7 +870,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_merge_sort_mutable() {
|
||||
pub pure fn le(a: &int, b: &int) -> bool { *a <= *b }
|
||||
let v1 = ~[mut 3, 2, 1];
|
||||
let mut v1 = ~[3, 2, 1];
|
||||
let v2 = merge_sort(v1, le);
|
||||
assert v2 == ~[1, 2, 3];
|
||||
}
|
||||
@ -923,7 +923,7 @@ mod test_tim_sort {
|
||||
pure fn ge(&self, other: &CVal) -> bool { (*self).val >= other.val }
|
||||
}
|
||||
|
||||
fn check_sort(v1: &[mut int], v2: &[mut int]) {
|
||||
fn check_sort(v1: &mut [int], v2: &mut [int]) {
|
||||
let len = vec::len::<int>(v1);
|
||||
tim_sort::<int>(v1);
|
||||
let mut i = 0u;
|
||||
@ -937,24 +937,24 @@ mod test_tim_sort {
|
||||
#[test]
|
||||
fn test() {
|
||||
{
|
||||
let v1 = ~[mut 3, 7, 4, 5, 2, 9, 5, 8];
|
||||
let v2 = ~[mut 2, 3, 4, 5, 5, 7, 8, 9];
|
||||
let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
|
||||
let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{
|
||||
let v1 = ~[mut 1, 1, 1];
|
||||
let v2 = ~[mut 1, 1, 1];
|
||||
let mut v1 = ~[1, 1, 1];
|
||||
let mut v2 = ~[1, 1, 1];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{
|
||||
let v1: ~[mut int] = ~[mut];
|
||||
let v2: ~[mut int] = ~[mut];
|
||||
let mut v1: ~[int] = ~[];
|
||||
let mut v2: ~[int] = ~[];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
{ let v1 = ~[mut 9]; let v2 = ~[mut 9]; check_sort(v1, v2); }
|
||||
{ let mut v1 = ~[9]; let mut v2 = ~[9]; check_sort(v1, v2); }
|
||||
{
|
||||
let v1 = ~[mut 9, 3, 3, 3, 9];
|
||||
let v2 = ~[mut 3, 3, 3, 9, 9];
|
||||
let mut v1 = ~[9, 3, 3, 3, 9];
|
||||
let mut v2 = ~[3, 3, 3, 9, 9];
|
||||
check_sort(v1, v2);
|
||||
}
|
||||
}
|
||||
@ -1019,12 +1019,12 @@ mod big_tests {
|
||||
tabulate_managed(low, high);
|
||||
}
|
||||
|
||||
fn multiplyVec<T: Copy>(arr: &[const T], num: uint) -> ~[mut 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]
|
||||
};
|
||||
vec::cast_to_mut(move res)
|
||||
move res
|
||||
}
|
||||
|
||||
fn makeRange(n: uint) -> ~[uint] {
|
||||
@ -1050,7 +1050,7 @@ mod big_tests {
|
||||
let arr = do vec::from_fn(n) |_i| {
|
||||
rng.gen_float()
|
||||
};
|
||||
let arr = vec::cast_to_mut(move arr);
|
||||
let mut arr = move arr;
|
||||
|
||||
tim_sort(arr); // *sort
|
||||
isSorted(arr);
|
||||
@ -1088,7 +1088,7 @@ mod big_tests {
|
||||
tim_sort(arr);
|
||||
isSorted(arr);
|
||||
|
||||
let arr = if n > 4 {
|
||||
let mut arr = if n > 4 {
|
||||
let part = vec::view(arr, 0, 4);
|
||||
multiplyVec(part, n)
|
||||
} else { move arr };
|
||||
@ -1122,7 +1122,7 @@ mod big_tests {
|
||||
let arr = do vec::from_fn(n) |_i| {
|
||||
@rng.gen_float()
|
||||
};
|
||||
let arr = vec::cast_to_mut(move arr);
|
||||
let mut arr = move arr;
|
||||
|
||||
tim_sort(arr); // *sort
|
||||
isSorted(arr);
|
||||
@ -1160,7 +1160,7 @@ mod big_tests {
|
||||
tim_sort(arr);
|
||||
isSorted(arr);
|
||||
|
||||
let arr = if n > 4 {
|
||||
let mut arr = if n > 4 {
|
||||
let part = vec::view(arr, 0, 4);
|
||||
multiplyVec(part, n)
|
||||
} else { move arr };
|
||||
|
@ -92,12 +92,12 @@ fn new_sem<Q: Owned>(count: int, q: Q) -> Sem<Q> {
|
||||
}
|
||||
#[doc(hidden)]
|
||||
fn new_sem_and_signal(count: int, num_condvars: uint)
|
||||
-> Sem<~[mut Waitqueue]> {
|
||||
-> Sem<~[Waitqueue]> {
|
||||
let mut queues = ~[];
|
||||
for num_condvars.times {
|
||||
queues.push(new_waitqueue());
|
||||
}
|
||||
new_sem(count, vec::cast_to_mut(move queues))
|
||||
new_sem(count, queues)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
@ -150,7 +150,7 @@ impl &Sem<()> {
|
||||
}
|
||||
}
|
||||
#[doc(hidden)]
|
||||
impl &Sem<~[mut Waitqueue]> {
|
||||
impl &Sem<~[Waitqueue]> {
|
||||
fn access<U>(blk: fn() -> U) -> U {
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
@ -166,7 +166,7 @@ impl &Sem<~[mut Waitqueue]> {
|
||||
// FIXME(#3588) should go inside of access()
|
||||
#[doc(hidden)]
|
||||
type SemRelease = SemReleaseGeneric<()>;
|
||||
type SemAndSignalRelease = SemReleaseGeneric<~[mut Waitqueue]>;
|
||||
type SemAndSignalRelease = SemReleaseGeneric<~[Waitqueue]>;
|
||||
struct SemReleaseGeneric<Q> { sem: &Sem<Q> }
|
||||
|
||||
impl<Q: Owned> SemReleaseGeneric<Q> : Drop {
|
||||
@ -181,7 +181,7 @@ fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r {
|
||||
}
|
||||
}
|
||||
|
||||
fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>)
|
||||
fn SemAndSignalRelease(sem: &r/Sem<~[Waitqueue]>)
|
||||
-> SemAndSignalRelease/&r {
|
||||
SemReleaseGeneric {
|
||||
sem: sem
|
||||
@ -189,7 +189,7 @@ fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>)
|
||||
}
|
||||
|
||||
/// A mechanism for atomic-unlock-and-deschedule blocking and signalling.
|
||||
pub struct Condvar { priv sem: &Sem<~[mut Waitqueue]> }
|
||||
pub struct Condvar { priv sem: &Sem<~[Waitqueue]> }
|
||||
|
||||
impl Condvar : Drop { fn finalize(&self) {} }
|
||||
|
||||
@ -259,7 +259,7 @@ impl &Condvar {
|
||||
// mutex during unwinding. As long as the wrapper (mutex, etc) is
|
||||
// bounded in when it gets released, this shouldn't hang forever.
|
||||
struct SemAndSignalReacquire {
|
||||
sem: &Sem<~[mut Waitqueue]>,
|
||||
sem: &Sem<~[Waitqueue]>,
|
||||
}
|
||||
|
||||
impl SemAndSignalReacquire : Drop {
|
||||
@ -273,7 +273,7 @@ impl &Condvar {
|
||||
}
|
||||
}
|
||||
|
||||
fn SemAndSignalReacquire(sem: &r/Sem<~[mut Waitqueue]>)
|
||||
fn SemAndSignalReacquire(sem: &r/Sem<~[Waitqueue]>)
|
||||
-> SemAndSignalReacquire/&r {
|
||||
SemAndSignalReacquire {
|
||||
sem: sem
|
||||
@ -345,7 +345,7 @@ fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl &Sem<~[mut Waitqueue]> {
|
||||
impl &Sem<~[Waitqueue]> {
|
||||
// The only other place that condvars get built is rwlock_write_mode.
|
||||
fn access_cond<U>(blk: fn(c: &Condvar) -> U) -> U {
|
||||
do self.access { blk(&Condvar { sem: self }) }
|
||||
@ -400,7 +400,7 @@ impl &Semaphore {
|
||||
* A task which fails while holding a mutex will unlock the mutex as it
|
||||
* unwinds.
|
||||
*/
|
||||
struct Mutex { priv sem: Sem<~[mut Waitqueue]> }
|
||||
struct Mutex { priv sem: Sem<~[Waitqueue]> }
|
||||
|
||||
/// Create a new mutex, with one associated condvar.
|
||||
pub fn Mutex() -> Mutex { mutex_with_condvars(1) }
|
||||
@ -450,7 +450,7 @@ struct RWlockInner {
|
||||
*/
|
||||
struct RWlock {
|
||||
priv order_lock: Semaphore,
|
||||
priv access_lock: Sem<~[mut Waitqueue]>,
|
||||
priv access_lock: Sem<~[Waitqueue]>,
|
||||
priv state: Exclusive<RWlockInner>
|
||||
}
|
||||
|
||||
|
@ -269,9 +269,9 @@ pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
|
||||
}
|
||||
|
||||
// This is sort of stupid here, converting to a vec of mutables and back
|
||||
let v: ~[mut @ast::meta_item] = vec::cast_to_mut(items);
|
||||
let mut v: ~[@ast::meta_item] = items;
|
||||
std::sort::quick_sort(v, lteq);
|
||||
vec::cast_from_mut(move v)
|
||||
move v
|
||||
}
|
||||
|
||||
pub fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ~str) ->
|
||||
|
@ -194,7 +194,7 @@ pub fn Parser(sess: parse_sess,
|
||||
token: tok0.tok,
|
||||
span: span0,
|
||||
last_span: span0,
|
||||
buffer: [mut TokenAndSpan {tok: tok0.tok, sp: span0}, ..4],
|
||||
mut buffer: [TokenAndSpan {tok: tok0.tok, sp: span0}, ..4],
|
||||
buffer_start: 0,
|
||||
buffer_end: 0,
|
||||
tokens_consumed: 0u,
|
||||
@ -214,7 +214,7 @@ pub struct Parser {
|
||||
mut token: token::Token,
|
||||
mut span: span,
|
||||
mut last_span: span,
|
||||
mut buffer: [mut TokenAndSpan * 4],
|
||||
mut buffer: [TokenAndSpan * 4],
|
||||
mut buffer_start: int,
|
||||
mut buffer_end: int,
|
||||
mut tokens_consumed: uint,
|
||||
|
@ -119,7 +119,7 @@ pub fn tok_str(++t: token) -> ~str {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buf_str(toks: ~[mut token], szs: ~[mut int], left: uint, right: uint,
|
||||
pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint,
|
||||
lim: uint) -> ~str {
|
||||
let n = vec::len(toks);
|
||||
assert (n == vec::len(szs));
|
||||
@ -148,17 +148,17 @@ pub fn mk_printer(out: io::Writer, linewidth: uint) -> printer {
|
||||
// fall behind.
|
||||
let n: uint = 3 * linewidth;
|
||||
debug!("mk_printer %u", linewidth);
|
||||
let token: ~[mut token] = vec::cast_to_mut(vec::from_elem(n, EOF));
|
||||
let size: ~[mut int] = vec::cast_to_mut(vec::from_elem(n, 0));
|
||||
let scan_stack: ~[mut uint] = vec::cast_to_mut(vec::from_elem(n, 0u));
|
||||
let mut token: ~[token] = vec::from_elem(n, EOF);
|
||||
let mut size: ~[int] = vec::from_elem(n, 0);
|
||||
let mut scan_stack: ~[uint] = vec::from_elem(n, 0u);
|
||||
printer_(@{out: out,
|
||||
buf_len: n,
|
||||
mut margin: linewidth as int,
|
||||
mut space: linewidth as int,
|
||||
mut left: 0,
|
||||
mut right: 0,
|
||||
token: move token,
|
||||
size: move size,
|
||||
mut token: move token,
|
||||
mut size: move size,
|
||||
mut left_total: 0,
|
||||
mut right_total: 0,
|
||||
mut scan_stack: move scan_stack,
|
||||
@ -254,8 +254,8 @@ pub type printer_ = {
|
||||
mut space: int, // number of spaces left on line
|
||||
mut left: uint, // index of left side of input stream
|
||||
mut right: uint, // index of right side of input stream
|
||||
token: ~[mut token], // ring-buffr stream goes through
|
||||
size: ~[mut int], // ring-buffer of calculated sizes
|
||||
mut token: ~[token], // ring-buffr stream goes through
|
||||
mut size: ~[int], // ring-buffer of calculated sizes
|
||||
mut left_total: int, // running size of stream "...left"
|
||||
mut right_total: int, // running size of stream "...right"
|
||||
// pseudo-stack, really a ring too. Holds the
|
||||
@ -264,7 +264,7 @@ pub type printer_ = {
|
||||
// BEGIN (if there is any) on top of it. Stuff is flushed off the
|
||||
// bottom as it becomes irrelevant due to the primary ring-buffer
|
||||
// advancing.
|
||||
mut scan_stack: ~[mut uint],
|
||||
mut scan_stack: ~[uint],
|
||||
mut scan_stack_empty: bool, // top==bottom disambiguator
|
||||
mut top: uint, // index of top of scan_stack
|
||||
mut bottom: uint, // index of bottom of scan_stack
|
||||
|
@ -120,8 +120,8 @@ fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] {
|
||||
* Nodes that are unreachable have a parent of -1.
|
||||
*/
|
||||
fn bfs(graph: graph, key: node_id) -> bfs_result {
|
||||
let marks : ~[mut node_id]
|
||||
= vec::cast_to_mut(vec::from_elem(vec::len(graph), -1i64));
|
||||
let mut marks : ~[node_id]
|
||||
= vec::from_elem(vec::len(graph), -1i64);
|
||||
|
||||
let Q = deque::create();
|
||||
|
||||
@ -140,7 +140,7 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
|
||||
};
|
||||
}
|
||||
|
||||
vec::cast_from_mut(move marks)
|
||||
move marks
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 v = vec::cast_to_mut(vec::from_elem(vec::len(u), 0.0));
|
||||
eval_A_times_u(u, v);
|
||||
eval_At_times_u(v, AtAu);
|
||||
|
@ -30,7 +30,7 @@ use io::{ReaderUtil, WriterUtil};
|
||||
//
|
||||
|
||||
// internal type of sudoku grids
|
||||
type grid = ~[~[mut u8]];
|
||||
type grid = ~[~[u8]];
|
||||
|
||||
// exported type of sudoku grids
|
||||
pub enum grid_t { grid_ctor(grid), }
|
||||
@ -39,8 +39,8 @@ pub enum grid_t { grid_ctor(grid), }
|
||||
pub fn read_grid(f: io::Reader) -> grid_t {
|
||||
assert f.read_line() == ~"9,9"; /* assert first line is exactly "9,9" */
|
||||
|
||||
let g = vec::from_fn(10u, {|_i|
|
||||
vec::cast_to_mut(vec::from_elem(10u, 0 as u8))
|
||||
let mut g = vec::from_fn(10u, {|_i|
|
||||
vec::from_elem(10u, 0 as u8)
|
||||
});
|
||||
while !f.eof() {
|
||||
let comps = str::split_char(str::trim(f.read_line()), ',');
|
||||
@ -55,7 +55,7 @@ pub fn read_grid(f: io::Reader) -> grid_t {
|
||||
|
||||
// solve sudoku grid
|
||||
pub fn solve_grid(g: grid_t) {
|
||||
fn next_color(g: grid, row: u8, col: u8, start_color: u8) -> bool {
|
||||
fn next_color(mut g: grid, row: u8, col: u8, start_color: u8) -> bool {
|
||||
if start_color < 10u8 {
|
||||
// colors not yet used
|
||||
let avail = bitv::Bitv(10u, false);
|
||||
@ -139,8 +139,8 @@ fn main() {
|
||||
let grid = if vec::len(args) == 1u {
|
||||
// FIXME create sudoku inline since nested vec consts dont work yet
|
||||
// (#3733)
|
||||
let g = vec::from_fn(10u, |_i| {
|
||||
vec::cast_to_mut(vec::from_elem(10u, 0 as u8))
|
||||
let mut g = vec::from_fn(10u, |_i| {
|
||||
vec::from_elem(10u, 0 as u8)
|
||||
});
|
||||
g[0][1] = 4u8;
|
||||
g[0][3] = 6u8;
|
||||
|
@ -14,10 +14,10 @@ fn want_slice(v: &[int]) -> int {
|
||||
return sum;
|
||||
}
|
||||
|
||||
fn has_mut_vec(+v: ~[mut int]) -> int {
|
||||
fn has_mut_vec(+v: ~[int]) -> int {
|
||||
want_slice(v)
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
assert has_mut_vec(~[mut 1, 2, 3]) == 6;
|
||||
assert has_mut_vec(~[1, 2, 3]) == 6;
|
||||
}
|
@ -4,7 +4,7 @@ pure fn sum(x: &[int]) -> int {
|
||||
return sum;
|
||||
}
|
||||
|
||||
fn sum_mut(y: &[mut int]) -> int {
|
||||
fn sum_mut(y: &mut [int]) -> int {
|
||||
sum(y)
|
||||
}
|
||||
|
||||
@ -16,4 +16,4 @@ fn sum_const(y: &[const int]) -> int {
|
||||
sum(y)
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
pub fn main() {}
|
||||
|
@ -2,7 +2,7 @@ fn foo(v: &[const uint]) -> ~[uint] {
|
||||
v.to_vec()
|
||||
}
|
||||
|
||||
fn bar(v: &[mut uint]) -> ~[uint] {
|
||||
fn bar(v: &mut [uint]) -> ~[uint] {
|
||||
v.to_vec()
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ trait Reverser {
|
||||
fn reverse(&self);
|
||||
}
|
||||
|
||||
fn bar(v: &[mut uint]) {
|
||||
fn bar(v: &mut [uint]) {
|
||||
vec::reverse(v);
|
||||
vec::reverse(v);
|
||||
vec::reverse(v);
|
||||
|
@ -2,13 +2,13 @@ trait Reverser {
|
||||
fn reverse(&self);
|
||||
}
|
||||
|
||||
impl &[mut uint] : Reverser {
|
||||
impl &mut [uint] : Reverser {
|
||||
fn reverse(&self) {
|
||||
vec::reverse(*self);
|
||||
}
|
||||
}
|
||||
|
||||
fn bar(v: &[mut uint]) {
|
||||
fn bar(v: &mut [uint]) {
|
||||
v.reverse();
|
||||
v.reverse();
|
||||
v.reverse();
|
||||
|
@ -10,4 +10,4 @@
|
||||
|
||||
|
||||
|
||||
pub fn main() { let v: ~[mut int] = ~[mut]; }
|
||||
pub fn main() { let mut v: ~[int] = ~[]; }
|
||||
|
@ -4,7 +4,7 @@ pub trait Reader {
|
||||
/// Read up to len bytes (or EOF) and put them into bytes (which
|
||||
/// must be at least len bytes long). Return number of bytes read.
|
||||
// FIXME (#2982): This should probably return an error.
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint;
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint;
|
||||
}
|
||||
|
||||
pub trait ReaderUtil {
|
||||
@ -16,7 +16,7 @@ pub trait ReaderUtil {
|
||||
impl<T: Reader> T : ReaderUtil {
|
||||
|
||||
fn read_bytes(&self, len: uint) {
|
||||
let count = self.read(&[mut 0], len);
|
||||
let mut count = self.read(&mut [0], len);
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,7 @@ struct S {
|
||||
}
|
||||
|
||||
impl S: Reader {
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ pub trait Reader {
|
||||
/// Read up to len bytes (or EOF) and put them into bytes (which
|
||||
/// must be at least len bytes long). Return number of bytes read.
|
||||
// FIXME (#2982): This should probably return an error.
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint;
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint;
|
||||
}
|
||||
|
||||
pub trait ReaderUtil {
|
||||
@ -16,7 +16,7 @@ pub trait ReaderUtil {
|
||||
impl<T: Reader> T : ReaderUtil {
|
||||
|
||||
fn read_bytes(&self, len: uint) {
|
||||
let count = self.read(&[mut 0], len);
|
||||
let mut count = self.read(&mut [0], len);
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,7 @@ struct S {
|
||||
}
|
||||
|
||||
impl S: Reader {
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ pub trait Reader {
|
||||
/// Read up to len bytes (or EOF) and put them into bytes (which
|
||||
/// must be at least len bytes long). Return number of bytes read.
|
||||
// FIXME (#2982): This should probably return an error.
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint;
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint;
|
||||
}
|
||||
|
||||
pub trait ReaderUtil {
|
||||
@ -16,7 +16,7 @@ pub trait ReaderUtil {
|
||||
impl<T: Reader> T : ReaderUtil {
|
||||
|
||||
fn read_bytes(len: uint) {
|
||||
let count = self.read(&[mut 0], len);
|
||||
let mut count = self.read(&mut [0], len);
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,7 @@ struct S {
|
||||
}
|
||||
|
||||
impl S: Reader {
|
||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
|
||||
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ pub trait Reader {
|
||||
/// Read up to len bytes (or EOF) and put them into bytes (which
|
||||
/// must be at least len bytes long). Return number of bytes read.
|
||||
// FIXME (#2982): This should probably return an error.
|
||||
fn read(bytes: &[mut u8], len: uint) -> uint;
|
||||
fn read(bytes: &mut [u8], len: uint) -> uint;
|
||||
}
|
||||
|
||||
pub trait ReaderUtil {
|
||||
@ -16,7 +16,7 @@ pub trait ReaderUtil {
|
||||
impl<T: Reader> T : ReaderUtil {
|
||||
|
||||
fn read_bytes(len: uint) {
|
||||
let count = self.read(&[mut 0], len);
|
||||
let mut count = self.read(&mut [0], len);
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,7 @@ struct S {
|
||||
}
|
||||
|
||||
impl S: Reader {
|
||||
fn read(bytes: &[mut u8], len: uint) -> uint {
|
||||
fn read(bytes: &mut [u8], len: uint) -> uint {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
fn two(it: fn(int)) { it(0); it(1); }
|
||||
|
||||
pub fn main() {
|
||||
let a: ~[mut int] = ~[mut -1, -1, -1, -1];
|
||||
let mut a: ~[int] = ~[-1, -1, -1, -1];
|
||||
let mut p: int = 0;
|
||||
do two |i| {
|
||||
do two |j| { a[p] = 10 * i + j; p += 1; }
|
||||
|
@ -21,6 +21,6 @@ pub fn main() {
|
||||
assert v.foo() == 1u;
|
||||
let v = ~[0];
|
||||
assert v.foo() == 1u;
|
||||
let v = ~[mut 0];
|
||||
let mut v = ~[0];
|
||||
assert v.foo() == 1u;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ struct AsciiArt
|
||||
width: uint,
|
||||
height: uint,
|
||||
priv fill: char,
|
||||
priv lines: ~[~[mut char]],
|
||||
priv lines: ~[~[char]],
|
||||
|
||||
// This struct can be quite large so we'll disable copying: developers need
|
||||
// to either pass these structs around via borrowed pointers or move them.
|
||||
@ -65,14 +65,14 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt
|
||||
{
|
||||
// Use an anonymous function to build a vector of vectors containing
|
||||
// blank characters for each position in our canvas.
|
||||
let lines = do vec::build_sized(height)
|
||||
let mut lines = do vec::build_sized(height)
|
||||
|push|
|
||||
{
|
||||
for height.times
|
||||
{
|
||||
let mut line = ~[];
|
||||
vec::grow_set(&mut line, width-1, &'.', '.');
|
||||
push(vec::cast_to_mut(line));
|
||||
push(line);
|
||||
}
|
||||
};
|
||||
|
||||
@ -84,7 +84,7 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt
|
||||
// Methods particular to the AsciiArt struct.
|
||||
impl AsciiArt
|
||||
{
|
||||
fn add_pt(x: int, y: int)
|
||||
fn add_pt(&mut self, x: int, y: int)
|
||||
{
|
||||
if x >= 0 && x < self.width as int
|
||||
{
|
||||
@ -99,7 +99,7 @@ impl AsciiArt
|
||||
// element is:
|
||||
// 1) potentially large
|
||||
// 2) needs to be modified
|
||||
let row = &self.lines[v];
|
||||
let row = &mut self.lines[v];
|
||||
row[h] = self.fill;
|
||||
}
|
||||
}
|
||||
@ -125,12 +125,12 @@ impl AsciiArt : ToStr
|
||||
#[allow(default_methods)]
|
||||
trait Canvas
|
||||
{
|
||||
fn add_point(shape: Point);
|
||||
fn add_rect(shape: Rect);
|
||||
fn add_point(&mut self, shape: Point);
|
||||
fn add_rect(&mut self, shape: Rect);
|
||||
|
||||
// Unlike interfaces traits support default implementations.
|
||||
// Got an ICE as soon as I added this method.
|
||||
fn add_points(shapes: &[Point])
|
||||
fn add_points(&mut self, shapes: &[Point])
|
||||
{
|
||||
for shapes.each |pt| {self.add_point(*pt)};
|
||||
}
|
||||
@ -141,12 +141,12 @@ trait Canvas
|
||||
// and code can use them polymorphically via the Canvas trait.
|
||||
impl AsciiArt : Canvas
|
||||
{
|
||||
fn add_point(shape: Point)
|
||||
fn add_point(&mut self, shape: Point)
|
||||
{
|
||||
self.add_pt(shape.x, shape.y);
|
||||
}
|
||||
|
||||
fn add_rect(shape: Rect)
|
||||
fn add_rect(&mut self, shape: Rect)
|
||||
{
|
||||
// Add the top and bottom lines.
|
||||
for int::range(shape.top_left.x, shape.top_left.x + shape.size.width)
|
||||
@ -188,7 +188,7 @@ fn test_ascii_art_ctor()
|
||||
|
||||
fn test_add_pt()
|
||||
{
|
||||
let art = AsciiArt(3, 3, '*');
|
||||
let mut art = AsciiArt(3, 3, '*');
|
||||
art.add_pt(0, 0);
|
||||
art.add_pt(0, -10);
|
||||
art.add_pt(1, 2);
|
||||
@ -198,7 +198,7 @@ fn test_add_pt()
|
||||
|
||||
fn test_shapes()
|
||||
{
|
||||
let art = AsciiArt(4, 4, '*');
|
||||
let mut art = AsciiArt(4, 4, '*');
|
||||
art.add_rect(Rect {top_left: Point {x: 0, y: 0}, size: Size {width: 4, height: 4}});
|
||||
art.add_point(Point {x: 2, y: 2});
|
||||
assert check_strs(art.to_str(), "****\n*..*\n*.**\n****");
|
||||
|
@ -15,12 +15,12 @@ enum option<T> {
|
||||
some(T),
|
||||
}
|
||||
|
||||
struct Smallintmap<T> {mut v: ~[mut option<T>]}
|
||||
struct Smallintmap<T> {mut v: ~[option<T>]}
|
||||
|
||||
struct V<T> { v: ~[mut option<T>] }
|
||||
struct V<T> { v: ~[option<T>] }
|
||||
|
||||
fn mk<T>() -> @Smallintmap<T> {
|
||||
let v: ~[mut option<T>] = ~[mut];
|
||||
let mut v: ~[option<T>] = ~[];
|
||||
return @Smallintmap {mut v: move v};
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,6 @@ fn len(v: ~[const int]) -> uint {
|
||||
pub fn main() {
|
||||
let v0 = ~[1, 2, 3, 4, 5];
|
||||
log(debug, len(v0));
|
||||
let v1 = ~[mut 1, 2, 3, 4, 5];
|
||||
let mut v1 = ~[1, 2, 3, 4, 5];
|
||||
log(debug, len(v1));
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ struct Pair { a: int, b: int}
|
||||
|
||||
pub fn main() {
|
||||
// This just tests whether the vec leaks its members.
|
||||
let pvec: ~[mut @Pair] =
|
||||
~[mut @Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}];
|
||||
let mut pvec: ~[@Pair] =
|
||||
~[@Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}];
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ pub fn main() {
|
||||
debug!("y==%d", y);
|
||||
assert y == 6;
|
||||
|
||||
let x = ~[mut 1, 2, 3];
|
||||
let mut x = ~[1, 2, 3];
|
||||
let y = x.sum();
|
||||
debug!("y==%d", y);
|
||||
assert y == 6;
|
||||
|
@ -8,10 +8,10 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn swap<T>(v: &[mut T], i: int, j: int) { v[i] <-> v[j]; }
|
||||
fn swap<T>(v: &mut [T], i: int, j: int) { v[i] <-> v[j]; }
|
||||
|
||||
pub fn main() {
|
||||
let a: ~[mut int] = ~[mut 0, 1, 2, 3, 4, 5, 6];
|
||||
let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6];
|
||||
swap(a, 2, 4);
|
||||
assert (a[2] == 4);
|
||||
assert (a[4] == 2);
|
||||
|
Loading…
Reference in New Issue
Block a user