Skip to content

Commit 3136fba

Browse files
committed
Removing some mutable fields in libstd
1 parent 5641777 commit 3136fba

File tree

7 files changed

+91
-92
lines changed

7 files changed

+91
-92
lines changed

src/libstd/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ struct RWARCInner<T> { lock: RWlock, failed: bool, data: T }
259259
*/
260260
struct RWARC<T> {
261261
x: SharedMutableState<RWARCInner<T>>,
262-
mut cant_nest: ()
262+
cant_nest: ()
263263
}
264264
265265
/// Create a reader/writer ARC with the supplied data.

src/libstd/json.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ pub fn to_pretty_str(json: &Json) -> ~str {
360360

361361
pub struct Parser {
362362
priv rdr: @io::Reader,
363-
priv mut ch: char,
364-
priv mut line: uint,
365-
priv mut col: uint,
363+
priv ch: char,
364+
priv line: uint,
365+
priv col: uint,
366366
}
367367

368368
/// Decode a json value from an io::reader
@@ -376,7 +376,7 @@ pub fn Parser(rdr: @io::Reader) -> Parser {
376376
}
377377

378378
pub impl Parser {
379-
fn parse(&self) -> Result<Json, Error> {
379+
fn parse(&mut self) -> Result<Json, Error> {
380380
match self.parse_value() {
381381
Ok(value) => {
382382
// Skip trailing whitespaces.
@@ -396,7 +396,7 @@ pub impl Parser {
396396
priv impl Parser {
397397
fn eof(&self) -> bool { self.ch == -1 as char }
398398

399-
fn bump(&self) {
399+
fn bump(&mut self) {
400400
self.ch = self.rdr.read_char();
401401

402402
if self.ch == '\n' {
@@ -407,7 +407,7 @@ priv impl Parser {
407407
}
408408
}
409409

410-
fn next_char(&self) -> char {
410+
fn next_char(&mut self) -> char {
411411
self.bump();
412412
self.ch
413413
}
@@ -416,7 +416,7 @@ priv impl Parser {
416416
Err(Error { line: self.line, col: self.col, msg: @msg })
417417
}
418418

419-
fn parse_value(&self) -> Result<Json, Error> {
419+
fn parse_value(&mut self) -> Result<Json, Error> {
420420
self.parse_whitespace();
421421

422422
if self.eof() { return self.error(~"EOF while parsing value"); }
@@ -437,11 +437,11 @@ priv impl Parser {
437437
}
438438
}
439439

440-
fn parse_whitespace(&self) {
440+
fn parse_whitespace(&mut self) {
441441
while char::is_whitespace(self.ch) { self.bump(); }
442442
}
443443

444-
fn parse_ident(&self, ident: &str, value: Json) -> Result<Json, Error> {
444+
fn parse_ident(&mut self, ident: &str, value: Json) -> Result<Json, Error> {
445445
if str::all(ident, |c| c == self.next_char()) {
446446
self.bump();
447447
Ok(value)
@@ -450,7 +450,7 @@ priv impl Parser {
450450
}
451451
}
452452

453-
fn parse_number(&self) -> Result<Json, Error> {
453+
fn parse_number(&mut self) -> Result<Json, Error> {
454454
let mut neg = 1f;
455455

456456
if self.ch == '-' {
@@ -480,7 +480,7 @@ priv impl Parser {
480480
Ok(Number(neg * res))
481481
}
482482

483-
fn parse_integer(&self) -> Result<float, Error> {
483+
fn parse_integer(&mut self) -> Result<float, Error> {
484484
let mut res = 0f;
485485

486486
match self.ch {
@@ -512,7 +512,7 @@ priv impl Parser {
512512
Ok(res)
513513
}
514514

515-
fn parse_decimal(&self, res: float) -> Result<float, Error> {
515+
fn parse_decimal(&mut self, res: float) -> Result<float, Error> {
516516
self.bump();
517517

518518
// Make sure a digit follows the decimal place.
@@ -538,10 +538,9 @@ priv impl Parser {
538538
Ok(res)
539539
}
540540

541-
fn parse_exponent(&self, res: float) -> Result<float, Error> {
541+
fn parse_exponent(&mut self, mut res: float) -> Result<float, Error> {
542542
self.bump();
543543

544-
let mut res = res;
545544
let mut exp = 0u;
546545
let mut neg_exp = false;
547546

@@ -579,7 +578,7 @@ priv impl Parser {
579578
Ok(res)
580579
}
581580

582-
fn parse_str(&self) -> Result<~str, Error> {
581+
fn parse_str(&mut self) -> Result<~str, Error> {
583582
let mut escape = false;
584583
let mut res = ~"";
585584

@@ -643,7 +642,7 @@ priv impl Parser {
643642
self.error(~"EOF while parsing string")
644643
}
645644

646-
fn parse_list(&self) -> Result<Json, Error> {
645+
fn parse_list(&mut self) -> Result<Json, Error> {
647646
self.bump();
648647
self.parse_whitespace();
649648

@@ -673,7 +672,7 @@ priv impl Parser {
673672
};
674673
}
675674

676-
fn parse_object(&self) -> Result<Json, Error> {
675+
fn parse_object(&mut self) -> Result<Json, Error> {
677676
self.bump();
678677
self.parse_whitespace();
679678

@@ -726,7 +725,8 @@ priv impl Parser {
726725

727726
/// Decodes a json value from an @io::Reader
728727
pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
729-
Parser(rdr).parse()
728+
let mut parser = Parser(rdr);
729+
parser.parse()
730730
}
731731

732732
/// Decodes a json value from a string

src/libstd/num/complex.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ mod test {
239239

240240
mod arith {
241241
use super::*;
242-
use super::super::*;
243242
use core::num::Zero;
244243

245244
#[test]

src/libstd/rope.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ pub mod iterator {
455455
node::Content(x) => return node::leaf_iterator::start(x)
456456
}
457457
}
458-
pub fn next(it: &node::leaf_iterator::T) -> Option<node::Leaf> {
458+
pub fn next(it: &mut node::leaf_iterator::T) -> Option<node::Leaf> {
459459
return node::leaf_iterator::next(it);
460460
}
461461
}
@@ -470,7 +470,7 @@ pub mod iterator {
470470
node::Content(x) => return node::char_iterator::start(x)
471471
}
472472
}
473-
pub fn next(it: &node::char_iterator::T) -> Option<char> {
473+
pub fn next(it: &mut node::char_iterator::T) -> Option<char> {
474474
return node::char_iterator::next(it)
475475
}
476476
}
@@ -832,9 +832,9 @@ pub mod node {
832832
unsafe {
833833
let mut buf = vec::from_elem(byte_len(node), 0);
834834
let mut offset = 0u;//Current position in the buffer
835-
let it = leaf_iterator::start(node);
835+
let mut it = leaf_iterator::start(node);
836836
loop {
837-
match (leaf_iterator::next(&it)) {
837+
match leaf_iterator::next(&mut it) {
838838
option::None => break,
839839
option::Some(x) => {
840840
//FIXME (#2744): Replace with memcpy or something similar
@@ -896,9 +896,9 @@ pub mod node {
896896
if height(node) < hint_max_node_height { return option::None; }
897897
//1. Gather all leaves as a forest
898898
let mut forest = ~[];
899-
let it = leaf_iterator::start(node);
899+
let mut it = leaf_iterator::start(node);
900900
loop {
901-
match (leaf_iterator::next(&it)) {
901+
match leaf_iterator::next(&mut it) {
902902
option::None => break,
903903
option::Some(x) => forest.push(@Leaf(x))
904904
}
@@ -1058,11 +1058,12 @@ pub mod node {
10581058
}
10591059

10601060
pub fn cmp(a: @Node, b: @Node) -> int {
1061-
let ita = char_iterator::start(a);
1062-
let itb = char_iterator::start(b);
1061+
let mut ita = char_iterator::start(a);
1062+
let mut itb = char_iterator::start(b);
10631063
let mut result = 0;
10641064
while result == 0 {
1065-
match ((char_iterator::next(&ita), char_iterator::next(&itb))) {
1065+
match (char_iterator::next(&mut ita), char_iterator::next(&mut itb))
1066+
{
10661067
(option::None, option::None) => break,
10671068
(option::Some(chara), option::Some(charb)) => {
10681069
result = char::cmp(chara, charb);
@@ -1131,9 +1132,7 @@ pub mod node {
11311132
* proportional to the height of the rope + the (bounded)
11321133
* length of the largest leaf.
11331134
*/
1134-
pub fn char_at(node: @Node, pos: uint) -> char {
1135-
let mut node = node;
1136-
let mut pos = pos;
1135+
pub fn char_at(mut node: @Node, mut pos: uint) -> char {
11371136
loop {
11381137
match *node {
11391138
Leaf(x) => return str::char_at(*x.content, pos),
@@ -1154,8 +1153,8 @@ pub mod node {
11541153
use core::vec;
11551154

11561155
pub struct T {
1157-
mut stack: ~[@Node],
1158-
mut stackpos: int,
1156+
stack: ~[@Node],
1157+
stackpos: int,
11591158
}
11601159

11611160
pub fn empty() -> T {
@@ -1171,7 +1170,7 @@ pub mod node {
11711170
}
11721171
}
11731172

1174-
pub fn next(it: &T) -> Option<Leaf> {
1173+
pub fn next(it: &mut T) -> Option<Leaf> {
11751174
if it.stackpos < 0 { return option::None; }
11761175
loop {
11771176
let current = it.stack[it.stackpos];
@@ -1199,8 +1198,8 @@ pub mod node {
11991198

12001199
pub struct T {
12011200
leaf_iterator: leaf_iterator::T,
1202-
mut leaf: Option<Leaf>,
1203-
mut leaf_byte_pos: uint,
1201+
leaf: Option<Leaf>,
1202+
leaf_byte_pos: uint,
12041203
}
12051204

12061205
pub fn start(node: @Node) -> T {
@@ -1219,13 +1218,13 @@ pub mod node {
12191218
}
12201219
}
12211220

1222-
pub fn next(it: &T) -> Option<char> {
1221+
pub fn next(it: &mut T) -> Option<char> {
12231222
loop {
1224-
match (get_current_or_next_leaf(it)) {
1223+
match get_current_or_next_leaf(it) {
12251224
option::None => return option::None,
12261225
option::Some(_) => {
12271226
let next_char = get_next_char_in_leaf(it);
1228-
match (next_char) {
1227+
match next_char {
12291228
option::None => loop,
12301229
option::Some(_) => return next_char
12311230
}
@@ -1234,30 +1233,30 @@ pub mod node {
12341233
};
12351234
}
12361235

1237-
pub fn get_current_or_next_leaf(it: &T) -> Option<Leaf> {
1238-
match ((*it).leaf) {
1239-
option::Some(_) => return (*it).leaf,
1236+
pub fn get_current_or_next_leaf(it: &mut T) -> Option<Leaf> {
1237+
match it.leaf {
1238+
option::Some(_) => return it.leaf,
12401239
option::None => {
1241-
let next = leaf_iterator::next(&((*it).leaf_iterator));
1242-
match (next) {
1240+
let next = leaf_iterator::next(&mut it.leaf_iterator);
1241+
match next {
12431242
option::None => return option::None,
12441243
option::Some(_) => {
1245-
(*it).leaf = next;
1246-
(*it).leaf_byte_pos = 0u;
1244+
it.leaf = next;
1245+
it.leaf_byte_pos = 0u;
12471246
return next;
12481247
}
12491248
}
12501249
}
12511250
}
12521251
}
12531252

1254-
pub fn get_next_char_in_leaf(it: &T) -> Option<char> {
1255-
match copy (*it).leaf {
1253+
pub fn get_next_char_in_leaf(it: &mut T) -> Option<char> {
1254+
match copy it.leaf {
12561255
option::None => return option::None,
12571256
option::Some(aleaf) => {
1258-
if (*it).leaf_byte_pos >= aleaf.byte_len {
1257+
if it.leaf_byte_pos >= aleaf.byte_len {
12591258
//We are actually past the end of the leaf
1260-
(*it).leaf = option::None;
1259+
it.leaf = option::None;
12611260
return option::None
12621261
} else {
12631262
let range =
@@ -1342,11 +1341,11 @@ mod tests {
13421341
assert!(rope_to_string(r) == *sample);
13431342

13441343
let mut string_iter = 0u;
1345-
let string_len = str::len(*sample);
1346-
let rope_iter = iterator::char::start(r);
1347-
let mut equal = true;
1344+
let string_len = str::len(*sample);
1345+
let mut rope_iter = iterator::char::start(r);
1346+
let mut equal = true;
13481347
while equal {
1349-
match (node::char_iterator::next(&rope_iter)) {
1348+
match (node::char_iterator::next(&mut rope_iter)) {
13501349
option::None => {
13511350
if string_iter < string_len {
13521351
equal = false;
@@ -1376,9 +1375,9 @@ mod tests {
13761375
let r = of_str(sample);
13771376

13781377
let mut len = 0u;
1379-
let it = iterator::char::start(r);
1378+
let mut it = iterator::char::start(r);
13801379
loop {
1381-
match (node::char_iterator::next(&it)) {
1380+
match (node::char_iterator::next(&mut it)) {
13821381
option::None => break,
13831382
option::Some(_) => len += 1u
13841383
}

src/libstd/sync.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn broadcast_waitqueue(q: &Waitqueue) -> uint {
7272
// The building-block used to make semaphores, mutexes, and rwlocks.
7373
#[doc(hidden)]
7474
struct SemInner<Q> {
75-
mut count: int,
75+
count: int,
7676
waiters: Waitqueue,
7777
// Can be either unit or another waitqueue. Some sems shouldn't come with
7878
// a condition variable attached, others should.
@@ -729,7 +729,6 @@ mod tests {
729729
730730
use core::cast;
731731
use core::cell::Cell;
732-
use core::option;
733732
use core::ptr;
734733
use core::result;
735734
use core::task;

src/libstd/task_pool.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ enum Msg<T> {
2626

2727
pub struct TaskPool<T> {
2828
channels: ~[Chan<Msg<T>>],
29-
mut next_index: uint,
30-
29+
next_index: uint,
3130
}
3231

3332
#[unsafe_destructor]
@@ -84,7 +83,7 @@ pub impl<T> TaskPool<T> {
8483

8584
/// Executes the function `f` on a task in the pool. The function
8685
/// receives a reference to the local data returned by the `init_fn`.
87-
fn execute(&self, f: ~fn(&T)) {
86+
fn execute(&mut self, f: ~fn(&T)) {
8887
self.channels[self.next_index].send(Execute(f));
8988
self.next_index += 1;
9089
if self.next_index == self.channels.len() { self.next_index = 0; }
@@ -97,7 +96,7 @@ fn test_task_pool() {
9796
let g: ~fn(uint) -> uint = |i| i;
9897
g
9998
};
100-
let pool = TaskPool::new(4, Some(SingleThreaded), f);
99+
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
101100
for 8.times {
102101
pool.execute(|i| io::println(fmt!("Hello from thread %u!", *i)));
103102
}

0 commit comments

Comments
 (0)