Skip to content

Commit 537889a

Browse files
committed
Fix type inference problems in tests and docs
1 parent da8023d commit 537889a

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/doc/intro.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,12 @@ use std::sync::{Arc,Mutex};
480480
fn main() {
481481
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));
482482
483-
for i in 0..3 {
483+
for i in 0us..3 {
484484
let number = numbers.clone();
485485
Thread::spawn(move || {
486486
let mut array = number.lock().unwrap();
487-
488-
array[i as usize] += 1;
489-
490-
println!("numbers[{}] is {}", i, array[i as usize]);
487+
array[i] += 1;
488+
println!("numbers[{}] is {}", i, array[i]);
491489
});
492490
}
493491
}

src/doc/trpl/looping.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ We now loop forever with `loop` and use `break` to break out early.
123123
iteration. This will only print the odd numbers:
124124

125125
```{rust}
126-
for x in 0..10 {
126+
for x in 0u32..10 {
127127
if x % 2 == 0 { continue; }
128128
129129
println!("{}", x);

src/doc/trpl/threads.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ for init_val in 0 .. 3 {
179179
}
180180

181181
let result = rx.recv().unwrap() + rx.recv().unwrap() + rx.recv().unwrap();
182-
# fn some_expensive_computation(_i: u32) -> u32 { 42 }
182+
# fn some_expensive_computation(_i: i32) -> i32 { 42 }
183183
```
184184

185185
Cloning a `Sender` produces a new handle to the same channel, allowing multiple
@@ -207,7 +207,7 @@ let rxs = (0 .. 3).map(|&:init_val| {
207207

208208
// Wait on each port, accumulating the results
209209
let result = rxs.iter().fold(0, |&:accum, rx| accum + rx.recv().unwrap() );
210-
# fn some_expensive_computation(_i: u32) -> u32 { 42 }
210+
# fn some_expensive_computation(_i: i32) -> i32 { 42 }
211211
```
212212

213213
## Backgrounding computations: Futures

src/test/bench/shootout-binarytrees.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
extern crate arena;
4242

4343
use std::iter::range_step;
44-
use std::thread::Thread;
44+
use std::thread::{Thread, JoinGuard};
4545
use arena::TypedArena;
4646

4747
struct Tree<'a> {
@@ -71,6 +71,18 @@ fn bottom_up_tree<'r>(arena: &'r TypedArena<Tree<'r>>, item: i32, depth: i32)
7171
}
7272
}
7373

74+
fn inner(depth: i32, iterations: i32) -> String {
75+
let mut chk = 0;
76+
for i in 1 .. iterations + 1 {
77+
let arena = TypedArena::new();
78+
let a = bottom_up_tree(&arena, i, depth);
79+
let b = bottom_up_tree(&arena, -i, depth);
80+
chk += item_check(&a) + item_check(&b);
81+
}
82+
format!("{}\t trees of depth {}\t check: {}",
83+
iterations * 2, depth, chk)
84+
}
85+
7486
fn main() {
7587
let args = std::os::args();
7688
let args = args.as_slice();
@@ -97,20 +109,10 @@ fn main() {
97109
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
98110

99111
let messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
100-
use std::num::Int;
101-
let iterations = 2.pow((max_depth - depth + min_depth) as usize);
102-
Thread::scoped(move|| {
103-
let mut chk = 0;
104-
for i in 1 .. iterations + 1 {
105-
let arena = TypedArena::new();
106-
let a = bottom_up_tree(&arena, i, depth);
107-
let b = bottom_up_tree(&arena, -i, depth);
108-
chk += item_check(&a) + item_check(&b);
109-
}
110-
format!("{}\t trees of depth {}\t check: {}",
111-
iterations * 2, depth, chk)
112-
})
113-
}).collect::<Vec<_>>();
112+
use std::num::Int;
113+
let iterations = 2.pow((max_depth - depth + min_depth) as usize);
114+
Thread::scoped(move || inner(depth, iterations))
115+
}).collect::<Vec<_>>();
114116

115117
for message in messages.into_iter() {
116118
println!("{}", message.join().ok().unwrap());

0 commit comments

Comments
 (0)