mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-01 07:13:24 +03:00
Replace 'mutable?' with 'const'
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 */ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ fn mt_to_str(cx: ctxt, m: mt) -> 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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ fn file_reader(path: str) -> result::t<reader, str> {
|
||||
|
||||
// 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) {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
|
||||
Create a list from a vector
|
||||
*/
|
||||
fn from_vec<T>(v: [mutable? T]) -> list<T> {
|
||||
fn from_vec<T>(v: [const T]) -> list<T> {
|
||||
*vec::foldr({ |h, t| @cons(h, t) }, @nil::<T>, v)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
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<T>(le: lteq<T>, v: [mutable? T]) -> [T] {
|
||||
fn merge_sort<T>(le: lteq<T>, v: [const T]) -> [T] {
|
||||
fn merge<T>(le: lteq<T>, a: [T], b: [T]) -> [T] {
|
||||
let rs: [T] = [];
|
||||
let a_len: uint = len::<T>(a);
|
||||
|
||||
+1
-1
@@ -189,7 +189,7 @@ fn bytes(s: str) -> [u8] unsafe {
|
||||
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);
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ fn union(ufnd: ufind, m: uint, n: uint) {
|
||||
|
||||
// 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::<node>(ufnd.nodes);
|
||||
while len != n { vec::pop::<node>(ufnd.nodes); len -= 1u; }
|
||||
|
||||
+31
-31
@@ -8,13 +8,13 @@
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
native mod rusti {
|
||||
fn vec_len<T>(&&v: [mutable? T]) -> uint;
|
||||
fn vec_len<T>(&&v: [const T]) -> uint;
|
||||
}
|
||||
|
||||
#[abi = "cdecl"]
|
||||
native mod rustrt {
|
||||
fn vec_reserve_shared<T>(t: *sys::type_desc,
|
||||
&v: [mutable? T],
|
||||
&v: [const T],
|
||||
n: uint);
|
||||
fn vec_from_buf_shared<T>(t: *sys::type_desc,
|
||||
ptr: *T,
|
||||
@@ -34,7 +34,7 @@ fn vec_from_buf_shared<T>(t: *sys::type_desc,
|
||||
|
||||
Returns true if a vector contains no elements.
|
||||
*/
|
||||
pure fn is_empty<T>(v: [mutable? T]) -> bool {
|
||||
pure fn is_empty<T>(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 @@ fn vec_from_buf_shared<T>(t: *sys::type_desc,
|
||||
|
||||
Returns true if a vector contains some elements.
|
||||
*/
|
||||
pure fn is_not_empty<T>(v: [mutable? T]) -> bool { ret !is_empty(v); }
|
||||
pure fn is_not_empty<T>(v: [const T]) -> bool { ret !is_empty(v); }
|
||||
|
||||
/*
|
||||
Predicate: same_length
|
||||
@@ -69,7 +69,7 @@ fn vec_from_buf_shared<T>(t: *sys::type_desc,
|
||||
v - A vector
|
||||
n - The number of elements to reserve space for
|
||||
*/
|
||||
fn reserve<T>(&v: [mutable? T], n: uint) {
|
||||
fn reserve<T>(&v: [const T], n: uint) {
|
||||
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), v, n);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ fn reserve<T>(&v: [mutable? T], n: uint) {
|
||||
|
||||
Returns the length of a vector
|
||||
*/
|
||||
pure fn len<T>(v: [mutable? T]) -> uint { unchecked { rusti::vec_len(v) } }
|
||||
pure fn len<T>(v: [const T]) -> uint { unchecked { rusti::vec_len(v) } }
|
||||
|
||||
/*
|
||||
Function: init_fn
|
||||
@@ -181,7 +181,7 @@ fn from_mut<T>(v: [mutable T]) -> [T] {
|
||||
Predicates:
|
||||
<is_not_empty> (v)
|
||||
*/
|
||||
fn head<T>(v: [mutable? T]) : is_not_empty(v) -> T { ret v[0]; }
|
||||
fn head<T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
|
||||
|
||||
/*
|
||||
Function: tail
|
||||
@@ -191,7 +191,7 @@ fn from_mut<T>(v: [mutable T]) -> [T] {
|
||||
Predicates:
|
||||
<is_not_empty> (v)
|
||||
*/
|
||||
fn tail<T>(v: [mutable? T]) : is_not_empty(v) -> [T] {
|
||||
fn tail<T>(v: [const T]) : is_not_empty(v) -> [T] {
|
||||
ret slice(v, 1u, len(v));
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ fn tail<T>(v: [mutable? T]) : is_not_empty(v) -> [T] {
|
||||
Preconditions:
|
||||
`v` is not empty
|
||||
*/
|
||||
fn init<T>(v: [mutable? T]) -> [T] {
|
||||
fn init<T>(v: [const T]) -> [T] {
|
||||
assert len(v) != 0u;
|
||||
slice(v, 0u, len(v) - 1u)
|
||||
}
|
||||
@@ -221,7 +221,7 @@ fn init<T>(v: [mutable? T]) -> [T] {
|
||||
An option containing the last element of `v` if `v` is not empty, or
|
||||
none if `v` is empty.
|
||||
*/
|
||||
fn last<T>(v: [mutable? T]) -> option::t<T> {
|
||||
fn last<T>(v: [const T]) -> option::t<T> {
|
||||
if len(v) == 0u { ret none; }
|
||||
ret some(v[len(v) - 1u]);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ fn last<T>(v: [mutable? T]) -> option::t<T> {
|
||||
Predicates:
|
||||
<is_not_empty> (v)
|
||||
*/
|
||||
fn last_total<T>(v: [mutable? T]) : is_not_empty(v) -> T {
|
||||
fn last_total<T>(v: [const T]) : is_not_empty(v) -> T {
|
||||
ret v[len(v) - 1u];
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ fn last_total<T>(v: [mutable? T]) : is_not_empty(v) -> T {
|
||||
|
||||
Returns a copy of the elements from [`start`..`end`) from `v`.
|
||||
*/
|
||||
fn slice<T>(v: [mutable? T], start: uint, end: uint) -> [T] {
|
||||
fn slice<T>(v: [const T], start: uint, end: uint) -> [T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let result = [];
|
||||
@@ -259,7 +259,7 @@ fn slice<T>(v: [mutable? T], start: uint, end: uint) -> [T] {
|
||||
|
||||
Returns a copy of the elements from [`start`..`end`) from `v`.
|
||||
*/
|
||||
fn slice_mut<T>(v: [mutable? T], start: uint, end: uint) -> [mutable T] {
|
||||
fn slice_mut<T>(v: [const T], start: uint, end: uint) -> [mutable T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let result = [mutable];
|
||||
@@ -277,7 +277,7 @@ fn slice_mut<T>(v: [mutable? T], start: uint, end: uint) -> [mutable T] {
|
||||
|
||||
Removes the first element from a vector and return it
|
||||
*/
|
||||
fn shift<T>(&v: [mutable? T]) -> T {
|
||||
fn shift<T>(&v: [const T]) -> T {
|
||||
let ln = len::<T>(v);
|
||||
assert (ln > 0u);
|
||||
let e = v[0];
|
||||
@@ -291,7 +291,7 @@ fn shift<T>(&v: [mutable? T]) -> T {
|
||||
|
||||
Remove the last element from a vector and return it
|
||||
*/
|
||||
fn pop<T>(&v: [mutable? T]) -> T {
|
||||
fn pop<T>(&v: [const T]) -> T {
|
||||
let ln = len(v);
|
||||
assert (ln > 0u);
|
||||
ln -= 1u;
|
||||
@@ -323,7 +323,7 @@ fn grow<T>(&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 @@ fn grow_set<T>(&v: [mutable T], index: uint, initval: T, val: T) {
|
||||
|
||||
Apply a function to each element of a vector and return the results
|
||||
*/
|
||||
fn map<T, U>(f: block(T) -> U, v: [mutable? T]) -> [U] {
|
||||
fn map<T, U>(f: block(T) -> U, v: [const T]) -> [U] {
|
||||
let result = [];
|
||||
reserve(result, len(v));
|
||||
for elem: T in v {
|
||||
@@ -416,7 +416,7 @@ fn map2<T, U, V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] {
|
||||
If function `f` returns `none` then that element is excluded from
|
||||
the resulting vector.
|
||||
*/
|
||||
fn filter_map<T, U>(f: block(T) -> option::t<U>, v: [mutable? T]) -> [U] {
|
||||
fn filter_map<T, U>(f: block(T) -> option::t<U>, v: [const T]) -> [U] {
|
||||
let result = [];
|
||||
for elem: T in v {
|
||||
let elem2 = elem; // satisfies alias checker
|
||||
@@ -437,7 +437,7 @@ fn filter_map<T, U>(f: block(T) -> option::t<U>, v: [mutable? T]) -> [U] {
|
||||
Apply function `f` to each element of `v` and return a vector containing
|
||||
only those elements for which `f` returned true.
|
||||
*/
|
||||
fn filter<T>(f: block(T) -> bool, v: [mutable? T]) -> [T] {
|
||||
fn filter<T>(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 @@ fn filter<T>(f: block(T) -> bool, v: [mutable? T]) -> [T] {
|
||||
Concatenate a vector of vectors. Flattens a vector of vectors of T into
|
||||
a single vector of T.
|
||||
*/
|
||||
fn concat<T>(v: [mutable? [mutable? T]]) -> [T] {
|
||||
fn concat<T>(v: [const [const T]]) -> [T] {
|
||||
// FIXME: So much copying
|
||||
let new: [T] = [];
|
||||
for inner: [T] in v { new += inner; }
|
||||
@@ -466,7 +466,7 @@ fn concat<T>(v: [mutable? [mutable? T]]) -> [T] {
|
||||
|
||||
Reduce a vector from left to right
|
||||
*/
|
||||
fn foldl<T, U>(p: block(T, U) -> T, z: T, v: [mutable? U]) -> T {
|
||||
fn foldl<T, U>(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 @@ fn foldl<T, U>(p: block(T, U) -> T, z: T, v: [mutable? U]) -> T {
|
||||
|
||||
Reduce a vector from right to left
|
||||
*/
|
||||
fn foldr<T, U>(p: block(T, U) -> U, z: U, v: [mutable? T]) -> U {
|
||||
fn foldr<T, U>(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 @@ fn member<T>(x: T, v: [T]) -> bool {
|
||||
|
||||
Returns the number of elements that are equal to a given value
|
||||
*/
|
||||
fn count<T>(x: T, v: [mutable? T]) -> uint {
|
||||
fn count<T>(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 @@ fn reverse<T>(v: [mutable T]) {
|
||||
|
||||
Returns a vector with the order of elements reversed
|
||||
*/
|
||||
fn reversed<T>(v: [mutable? T]) -> [T] {
|
||||
fn reversed<T>(v: [const T]) -> [T] {
|
||||
let rs: [T] = [];
|
||||
let i = len::<T>(v);
|
||||
if i == 0u { ret rs; } else { i -= 1u; }
|
||||
@@ -690,7 +690,7 @@ fn enum_uints(start: uint, end: uint) : uint::le(start, end) -> [uint] {
|
||||
element's value.
|
||||
|
||||
*/
|
||||
fn iter<T>(v: [mutable? T], f: block(T)) {
|
||||
fn iter<T>(v: [const T], f: block(T)) {
|
||||
iter2(v) { |_i, v| f(v) }
|
||||
}
|
||||
|
||||
@@ -702,7 +702,7 @@ fn iter<T>(v: [mutable? T], f: block(T)) {
|
||||
Iterates over vector `v` and, for each element, calls function `f` with the
|
||||
element's value and index.
|
||||
*/
|
||||
fn iter2<T>(v: [mutable? T], f: block(uint, T)) {
|
||||
fn iter2<T>(v: [const T], f: block(uint, T)) {
|
||||
let i = 0u;
|
||||
for x in v { f(i, x); i += 1u; }
|
||||
}
|
||||
@@ -716,7 +716,7 @@ fn iter2<T>(v: [mutable? T], f: block(uint, T)) {
|
||||
element's value.
|
||||
|
||||
*/
|
||||
fn riter<T>(v: [mutable? T], f: block(T)) {
|
||||
fn riter<T>(v: [const T], f: block(T)) {
|
||||
riter2(v) { |_i, v| f(v) }
|
||||
}
|
||||
|
||||
@@ -728,7 +728,7 @@ fn riter<T>(v: [mutable? T], f: block(T)) {
|
||||
Iterates over vector `v` and, for each element, calls function `f` with the
|
||||
element's value and index.
|
||||
*/
|
||||
fn riter2<T>(v: [mutable? T], f: block(uint, T)) {
|
||||
fn riter2<T>(v: [const T], f: block(uint, T)) {
|
||||
let i = len(v);
|
||||
while 0u < i {
|
||||
i -= 1u;
|
||||
@@ -746,7 +746,7 @@ fn riter2<T>(v: [mutable? T], f: block(uint, T)) {
|
||||
The total number of permutations produced is `len(v)!`. If `v` contains
|
||||
repeated elements, then some permutations are repeated.
|
||||
*/
|
||||
fn permute<T>(v: [mutable? T], put: block([T])) {
|
||||
fn permute<T>(v: [const T], put: block([T])) {
|
||||
let ln = len(v);
|
||||
if ln == 0u {
|
||||
put([]);
|
||||
@@ -798,7 +798,7 @@ unsafe fn from_buf<T>(ptr: *T, elts: uint) -> [T] {
|
||||
modifing its buffers, so it is up to the caller to ensure that
|
||||
the vector is actually the specified size.
|
||||
*/
|
||||
unsafe fn set_len<T>(&v: [mutable? T], new_len: uint) {
|
||||
unsafe fn set_len<T>(&v: [const T], new_len: uint) {
|
||||
let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
(**repr).fill = new_len * sys::size_of::<T>();
|
||||
}
|
||||
@@ -814,7 +814,7 @@ unsafe fn set_len<T>(&v: [mutable? T], new_len: uint) {
|
||||
Modifying the vector may cause its buffer to be reallocated, which
|
||||
would also make any pointers to it invalid.
|
||||
*/
|
||||
unsafe fn to_ptr<T>(v: [mutable? T]) -> *T {
|
||||
unsafe fn to_ptr<T>(v: [const T]) -> *T {
|
||||
let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
ret ::unsafe::reinterpret_cast(addr_of((**repr).data));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
|
||||
fn push<T>(&v: [mutable? T], t: T) { v += [t]; }
|
||||
fn push<T>(&v: [const T], t: T) { v += [t]; }
|
||||
|
||||
fn main() { let v = [1, 2, 3]; push(v, 1); }
|
||||
|
||||
Reference in New Issue
Block a user