diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 4e393777d2a..3b2ba62ca93 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -746,8 +746,7 @@ fn parse_path_and_ty_param_substs(p: parser) -> ast::path { fn parse_mutability(p: parser) -> ast::mutability { if eat_word(p, "mutable") { - if p.peek() == token::QUES { p.bump(); ast::maybe_mut } - else { ast::mut } + ast::mut } else if eat_word(p, "const") { ast::maybe_mut } else { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index e2d829f5217..f65ca2fbd57 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1307,7 +1307,7 @@ fn print_op_maybe_parens(s: ps, expr: @ast::expr, outer_prec: int) { fn print_mutability(s: ps, mut: ast::mutability) { alt mut { ast::mut. { word_nbsp(s, "mutable"); } - ast::maybe_mut. { word_nbsp(s, "mutable?"); } + ast::maybe_mut. { word_nbsp(s, "const"); } ast::imm. {/* nothing */ } } } diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs index b148b99cde8..fe899b8c59a 100644 --- a/src/comp/util/ppaux.rs +++ b/src/comp/util/ppaux.rs @@ -84,7 +84,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str { alt m.mut { ast::mut. { mstr = "mutable "; } ast::imm. { mstr = ""; } - ast::maybe_mut. { mstr = "mutable? "; } + ast::maybe_mut. { mstr = "const "; } } ret mstr + ty_to_str(cx, m.ty); } diff --git a/src/lib/io.rs b/src/lib/io.rs index 78a5384db13..e3ff7ee0995 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -188,7 +188,7 @@ fn file_reader(path: str) -> result::t { // Byte buffer readers -// TODO: mutable? u8, but this fails with rustboot. +// TODO: const u8, but this fails with rustboot. type byte_buf = @{buf: [u8], mutable pos: uint}; obj byte_buf_reader(bbuf: byte_buf) { diff --git a/src/lib/list.rs b/src/lib/list.rs index 9ec762edd3d..6f51ab8e96c 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs @@ -25,7 +25,7 @@ Function: from_vec Create a list from a vector */ -fn from_vec(v: [mutable? T]) -> list { +fn from_vec(v: [const T]) -> list { *vec::foldr({ |h, t| @cons(h, t) }, @nil::, v) } diff --git a/src/lib/sort.rs b/src/lib/sort.rs index a4fe4cf3f8b..29c478472bd 100644 --- a/src/lib/sort.rs +++ b/src/lib/sort.rs @@ -20,7 +20,7 @@ Merge sort. Returns a new vector containing the sorted list. Has worst case O(n log n) performance, best case O(n), but is not space efficient. This is a stable sort. */ -fn merge_sort(le: lteq, v: [mutable? T]) -> [T] { +fn merge_sort(le: lteq, v: [const T]) -> [T] { fn merge(le: lteq, a: [T], b: [T]) -> [T] { let rs: [T] = []; let a_len: uint = len::(a); diff --git a/src/lib/str.rs b/src/lib/str.rs index 4184e8b2050..fb24c59f62f 100644 --- a/src/lib/str.rs +++ b/src/lib/str.rs @@ -189,7 +189,7 @@ Function: unsafe_from_bytes Converts a vector of bytes to a string. Does not verify that the vector contains valid UTF-8. */ -fn unsafe_from_bytes(v: [mutable? u8]) -> str unsafe { +fn unsafe_from_bytes(v: [const u8]) -> str unsafe { let vcopy: [u8] = v + [0u8]; let scopy: str = unsafe::reinterpret_cast(vcopy); unsafe::leak(vcopy); diff --git a/src/lib/ufind.rs b/src/lib/ufind.rs index d5d76d65ef4..7de70526a7f 100644 --- a/src/lib/ufind.rs +++ b/src/lib/ufind.rs @@ -44,7 +44,7 @@ fn set_count(ufnd: ufind) -> uint { ret vec::len::(ufnd.nodes); } // Removes all sets with IDs greater than or equal to the given value. fn prune(ufnd: ufind, n: uint) { - // TODO: Use "slice" once we get rid of "mutable?" + // TODO: Use "slice" once we get rid of "const" let len = vec::len::(ufnd.nodes); while len != n { vec::pop::(ufnd.nodes); len -= 1u; } diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 3d51560741b..cbe7f2cf8b3 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -8,13 +8,13 @@ import ptr::addr_of; #[abi = "rust-intrinsic"] native mod rusti { - fn vec_len(&&v: [mutable? T]) -> uint; + fn vec_len(&&v: [const T]) -> uint; } #[abi = "cdecl"] native mod rustrt { fn vec_reserve_shared(t: *sys::type_desc, - &v: [mutable? T], + &v: [const T], n: uint); fn vec_from_buf_shared(t: *sys::type_desc, ptr: *T, @@ -34,7 +34,7 @@ Predicate: is_empty Returns true if a vector contains no elements. */ -pure fn is_empty(v: [mutable? T]) -> bool { +pure fn is_empty(v: [const T]) -> bool { // FIXME: This would be easier if we could just call len for t: T in v { ret false; } ret true; @@ -45,7 +45,7 @@ Predicate: is_not_empty Returns true if a vector contains some elements. */ -pure fn is_not_empty(v: [mutable? T]) -> bool { ret !is_empty(v); } +pure fn is_not_empty(v: [const T]) -> bool { ret !is_empty(v); } /* Predicate: same_length @@ -69,7 +69,7 @@ Parameters: v - A vector n - The number of elements to reserve space for */ -fn reserve(&v: [mutable? T], n: uint) { +fn reserve(&v: [const T], n: uint) { rustrt::vec_reserve_shared(sys::get_type_desc::(), v, n); } @@ -78,7 +78,7 @@ Function: len Returns the length of a vector */ -pure fn len(v: [mutable? T]) -> uint { unchecked { rusti::vec_len(v) } } +pure fn len(v: [const T]) -> uint { unchecked { rusti::vec_len(v) } } /* Function: init_fn @@ -181,7 +181,7 @@ Returns the first element of a vector Predicates: (v) */ -fn head(v: [mutable? T]) : is_not_empty(v) -> T { ret v[0]; } +fn head(v: [const T]) : is_not_empty(v) -> T { ret v[0]; } /* Function: tail @@ -191,7 +191,7 @@ Returns all but the first element of a vector Predicates: (v) */ -fn tail(v: [mutable? T]) : is_not_empty(v) -> [T] { +fn tail(v: [const T]) : is_not_empty(v) -> [T] { ret slice(v, 1u, len(v)); } @@ -206,7 +206,7 @@ Returns all but the last elemnt of a vector Preconditions: `v` is not empty */ -fn init(v: [mutable? T]) -> [T] { +fn init(v: [const T]) -> [T] { assert len(v) != 0u; slice(v, 0u, len(v) - 1u) } @@ -221,7 +221,7 @@ Returns: An option containing the last element of `v` if `v` is not empty, or none if `v` is empty. */ -fn last(v: [mutable? T]) -> option::t { +fn last(v: [const T]) -> option::t { if len(v) == 0u { ret none; } ret some(v[len(v) - 1u]); } @@ -234,7 +234,7 @@ Returns the last element of a non-empty vector `v` Predicates: (v) */ -fn last_total(v: [mutable? T]) : is_not_empty(v) -> T { +fn last_total(v: [const T]) : is_not_empty(v) -> T { ret v[len(v) - 1u]; } @@ -243,7 +243,7 @@ Function: slice Returns a copy of the elements from [`start`..`end`) from `v`. */ -fn slice(v: [mutable? T], start: uint, end: uint) -> [T] { +fn slice(v: [const T], start: uint, end: uint) -> [T] { assert (start <= end); assert (end <= len(v)); let result = []; @@ -259,7 +259,7 @@ Function: slice_mut Returns a copy of the elements from [`start`..`end`) from `v`. */ -fn slice_mut(v: [mutable? T], start: uint, end: uint) -> [mutable T] { +fn slice_mut(v: [const T], start: uint, end: uint) -> [mutable T] { assert (start <= end); assert (end <= len(v)); let result = [mutable]; @@ -277,7 +277,7 @@ Function: shift Removes the first element from a vector and return it */ -fn shift(&v: [mutable? T]) -> T { +fn shift(&v: [const T]) -> T { let ln = len::(v); assert (ln > 0u); let e = v[0]; @@ -291,7 +291,7 @@ Function: pop Remove the last element from a vector and return it */ -fn pop(&v: [mutable? T]) -> T { +fn pop(&v: [const T]) -> T { let ln = len(v); assert (ln > 0u); ln -= 1u; @@ -323,7 +323,7 @@ fn grow(&v: [T], n: uint, initval: T) { } // TODO: Remove me once we have slots. -// FIXME: Can't grow take a [mutable? T] +// FIXME: Can't grow take a [const T] /* Function: grow_mut @@ -384,7 +384,7 @@ Function: map Apply a function to each element of a vector and return the results */ -fn map(f: block(T) -> U, v: [mutable? T]) -> [U] { +fn map(f: block(T) -> U, v: [const T]) -> [U] { let result = []; reserve(result, len(v)); for elem: T in v { @@ -416,7 +416,7 @@ Apply a function to each element of a vector and return the results If function `f` returns `none` then that element is excluded from the resulting vector. */ -fn filter_map(f: block(T) -> option::t, v: [mutable? T]) -> [U] { +fn filter_map(f: block(T) -> option::t, v: [const T]) -> [U] { let result = []; for elem: T in v { let elem2 = elem; // satisfies alias checker @@ -437,7 +437,7 @@ holds. Apply function `f` to each element of `v` and return a vector containing only those elements for which `f` returned true. */ -fn filter(f: block(T) -> bool, v: [mutable? T]) -> [T] { +fn filter(f: block(T) -> bool, v: [const T]) -> [T] { let result = []; for elem: T in v { let elem2 = elem; // satisfies alias checker @@ -454,7 +454,7 @@ Function: concat Concatenate a vector of vectors. Flattens a vector of vectors of T into a single vector of T. */ -fn concat(v: [mutable? [mutable? T]]) -> [T] { +fn concat(v: [const [const T]]) -> [T] { // FIXME: So much copying let new: [T] = []; for inner: [T] in v { new += inner; } @@ -466,7 +466,7 @@ Function: foldl Reduce a vector from left to right */ -fn foldl(p: block(T, U) -> T, z: T, v: [mutable? U]) -> T { +fn foldl(p: block(T, U) -> T, z: T, v: [const U]) -> T { let accum = z; iter(v) { |elt| accum = p(accum, elt); @@ -479,7 +479,7 @@ Function: foldr Reduce a vector from right to left */ -fn foldr(p: block(T, U) -> U, z: U, v: [mutable? T]) -> U { +fn foldr(p: block(T, U) -> U, z: U, v: [const T]) -> U { let accum = z; riter(v) { |elt| accum = p(elt, accum); @@ -526,7 +526,7 @@ Function: count Returns the number of elements that are equal to a given value */ -fn count(x: T, v: [mutable? T]) -> uint { +fn count(x: T, v: [const T]) -> uint { let cnt = 0u; for elt: T in v { if x == elt { cnt += 1u; } } ret cnt; @@ -646,7 +646,7 @@ Function: reversed Returns a vector with the order of elements reversed */ -fn reversed(v: [mutable? T]) -> [T] { +fn reversed(v: [const T]) -> [T] { let rs: [T] = []; let i = len::(v); if i == 0u { ret rs; } else { i -= 1u; } @@ -690,7 +690,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the element's value. */ -fn iter(v: [mutable? T], f: block(T)) { +fn iter(v: [const T], f: block(T)) { iter2(v) { |_i, v| f(v) } } @@ -702,7 +702,7 @@ Iterates over a vector's elements and indexes Iterates over vector `v` and, for each element, calls function `f` with the element's value and index. */ -fn iter2(v: [mutable? T], f: block(uint, T)) { +fn iter2(v: [const T], f: block(uint, T)) { let i = 0u; for x in v { f(i, x); i += 1u; } } @@ -716,7 +716,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the element's value. */ -fn riter(v: [mutable? T], f: block(T)) { +fn riter(v: [const T], f: block(T)) { riter2(v) { |_i, v| f(v) } } @@ -728,7 +728,7 @@ Iterates over a vector's elements and indexes in reverse Iterates over vector `v` and, for each element, calls function `f` with the element's value and index. */ -fn riter2(v: [mutable? T], f: block(uint, T)) { +fn riter2(v: [const T], f: block(uint, T)) { let i = len(v); while 0u < i { i -= 1u; @@ -746,7 +746,7 @@ is sorted then the permutations are lexicographically sorted). The total number of permutations produced is `len(v)!`. If `v` contains repeated elements, then some permutations are repeated. */ -fn permute(v: [mutable? T], put: block([T])) { +fn permute(v: [const T], put: block([T])) { let ln = len(v); if ln == 0u { put([]); @@ -798,7 +798,7 @@ mod unsafe { modifing its buffers, so it is up to the caller to ensure that the vector is actually the specified size. */ - unsafe fn set_len(&v: [mutable? T], new_len: uint) { + unsafe fn set_len(&v: [const T], new_len: uint) { let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).fill = new_len * sys::size_of::(); } @@ -814,7 +814,7 @@ mod unsafe { Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid. */ - unsafe fn to_ptr(v: [mutable? T]) -> *T { + unsafe fn to_ptr(v: [const T]) -> *T { let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); ret ::unsafe::reinterpret_cast(addr_of((**repr).data)); } diff --git a/src/test/compile-fail/mutable-huh-box-assign.rs b/src/test/compile-fail/mutable-huh-box-assign.rs index 9a3b35a47c6..1f06a82f9a6 100644 --- a/src/test/compile-fail/mutable-huh-box-assign.rs +++ b/src/test/compile-fail/mutable-huh-box-assign.rs @@ -1,7 +1,7 @@ // error-pattern: assigning to immutable box fn main() { - fn f(&&v: @mutable? int) { + fn f(&&v: @const int) { // This shouldn't be possible *v = 1 } diff --git a/src/test/compile-fail/mutable-huh-field-assign.rs b/src/test/compile-fail/mutable-huh-field-assign.rs index e6535c43f01..0aee89fb630 100644 --- a/src/test/compile-fail/mutable-huh-field-assign.rs +++ b/src/test/compile-fail/mutable-huh-field-assign.rs @@ -1,7 +1,7 @@ // error-pattern: assigning to immutable field fn main() { - fn f(&&v: {mutable? field: int}) { + fn f(&&v: {const field: int}) { // This shouldn't be possible v.field = 1 } diff --git a/src/test/compile-fail/mutable-huh-ptr-assign.rs b/src/test/compile-fail/mutable-huh-ptr-assign.rs index fdd2cbb9705..46f1ceee15d 100644 --- a/src/test/compile-fail/mutable-huh-ptr-assign.rs +++ b/src/test/compile-fail/mutable-huh-ptr-assign.rs @@ -3,7 +3,7 @@ use std; fn main() { - unsafe fn f(&&v: *mutable? int) { + unsafe fn f(&&v: *const int) { // This shouldn't be possible *v = 1 } diff --git a/src/test/compile-fail/mutable-huh-unique-assign.rs b/src/test/compile-fail/mutable-huh-unique-assign.rs index deb6adfb06c..6a0d81ca50b 100644 --- a/src/test/compile-fail/mutable-huh-unique-assign.rs +++ b/src/test/compile-fail/mutable-huh-unique-assign.rs @@ -1,7 +1,7 @@ // error-pattern: assigning to immutable box fn main() { - fn f(&&v: ~mutable? int) { + fn f(&&v: ~const int) { // This shouldn't be possible *v = 1 } diff --git a/src/test/compile-fail/mutable-huh-variance-box.rs b/src/test/compile-fail/mutable-huh-variance-box.rs index 72732a5d0b2..1715acc5859 100644 --- a/src/test/compile-fail/mutable-huh-variance-box.rs +++ b/src/test/compile-fail/mutable-huh-variance-box.rs @@ -3,7 +3,7 @@ fn main() { let v = @mutable [0]; - fn f(&&v: @mutable [mutable? int]) { + fn f(&&v: @mutable [const int]) { *v = [mutable 3] } diff --git a/src/test/compile-fail/mutable-huh-variance-deep.rs b/src/test/compile-fail/mutable-huh-variance-deep.rs index aafe0f1465d..072a1f04c8b 100644 --- a/src/test/compile-fail/mutable-huh-variance-deep.rs +++ b/src/test/compile-fail/mutable-huh-variance-deep.rs @@ -3,7 +3,7 @@ fn main() { let v = [mutable @mutable ~mutable [0]]; - fn f(&&v: [mutable @mutable ~mutable [mutable? int]]) { + fn f(&&v: [mutable @mutable ~mutable [const int]]) { } f(v); diff --git a/src/test/compile-fail/mutable-huh-variance-ptr.rs b/src/test/compile-fail/mutable-huh-variance-ptr.rs index 8f19ebd1dff..0cb05af444c 100644 --- a/src/test/compile-fail/mutable-huh-variance-ptr.rs +++ b/src/test/compile-fail/mutable-huh-variance-ptr.rs @@ -6,7 +6,7 @@ fn main() { let a = [0]; let v: *mutable [int] = std::ptr::mut_addr_of(a); - fn f(&&v: *mutable [mutable? int]) { + fn f(&&v: *mutable [const int]) { unsafe { *v = [mutable 3] } diff --git a/src/test/compile-fail/mutable-huh-variance-rec.rs b/src/test/compile-fail/mutable-huh-variance-rec.rs index 2225eb5c364..3bd079ba6ff 100644 --- a/src/test/compile-fail/mutable-huh-variance-rec.rs +++ b/src/test/compile-fail/mutable-huh-variance-rec.rs @@ -3,7 +3,7 @@ fn main() { let v = {mutable g: [0]}; - fn f(&&v: {mutable g: [mutable? int]}) { + fn f(&&v: {mutable g: [const int]}) { v.g = [mutable 3] } diff --git a/src/test/compile-fail/mutable-huh-variance-unique.rs b/src/test/compile-fail/mutable-huh-variance-unique.rs index ca3751629e3..54ffccecaf0 100644 --- a/src/test/compile-fail/mutable-huh-variance-unique.rs +++ b/src/test/compile-fail/mutable-huh-variance-unique.rs @@ -3,7 +3,7 @@ fn main() { let v = ~mutable [0]; - fn f(&&v: ~mutable [mutable? int]) { + fn f(&&v: ~mutable [const int]) { *v = [mutable 3] } diff --git a/src/test/compile-fail/mutable-huh-variance-vec1.rs b/src/test/compile-fail/mutable-huh-variance-vec1.rs index 0b834ab59d3..e688fe2c26e 100644 --- a/src/test/compile-fail/mutable-huh-variance-vec1.rs +++ b/src/test/compile-fail/mutable-huh-variance-vec1.rs @@ -3,7 +3,7 @@ fn main() { let v = [mutable [0]]; - fn f(&&v: [mutable [mutable? int]]) { + fn f(&&v: [mutable [const int]]) { v[0] = [mutable 3] } diff --git a/src/test/compile-fail/mutable-huh-variance-vec2.rs b/src/test/compile-fail/mutable-huh-variance-vec2.rs index c3b5c36d1d1..81422f047f4 100644 --- a/src/test/compile-fail/mutable-huh-variance-vec2.rs +++ b/src/test/compile-fail/mutable-huh-variance-vec2.rs @@ -3,7 +3,7 @@ fn main() { let v = [mutable [mutable 0]]; - fn f(&&v: [mutable [mutable? int]]) { + fn f(&&v: [mutable [const int]]) { v[0] = [3] } diff --git a/src/test/compile-fail/mutable-huh-variance-vec3.rs b/src/test/compile-fail/mutable-huh-variance-vec3.rs index dff3c1173fe..ef5da13a3af 100644 --- a/src/test/compile-fail/mutable-huh-variance-vec3.rs +++ b/src/test/compile-fail/mutable-huh-variance-vec3.rs @@ -3,7 +3,7 @@ fn main() { let v = [mutable [mutable [0]]]; - fn f(&&v: [mutable [mutable [mutable? int]]]) { + fn f(&&v: [mutable [mutable [const int]]]) { v[0][1] = [mutable 3] } diff --git a/src/test/compile-fail/mutable-huh-vec-assign.rs b/src/test/compile-fail/mutable-huh-vec-assign.rs index 1f273d376f1..43738008ec6 100644 --- a/src/test/compile-fail/mutable-huh-vec-assign.rs +++ b/src/test/compile-fail/mutable-huh-vec-assign.rs @@ -1,7 +1,7 @@ // error-pattern: assigning to immutable vec content fn main() { - fn f(&&v: [mutable? int]) { + fn f(&&v: [const int]) { // This shouldn't be possible v[0] = 1 } diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index 0e0d828bf63..8cdd5e82f18 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -1,5 +1,5 @@ -fn push(&v: [mutable? T], t: T) { v += [t]; } +fn push(&v: [const T], t: T) { v += [t]; } fn main() { let v = [1, 2, 3]; push(v, 1); }