Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: moving from int and uint to us for array access in examples #21277

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/doc/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn main() {

for i in 0..3 {
Thread::spawn(move || {
for j in 0..3 { numbers[j] += 1 }
for j in 0us..3 { numbers[j] += 1 }
});
}
}
Expand All @@ -438,15 +438,15 @@ It gives us this error:

```text
6:71 error: capture of moved value: `numbers`
for j in 0..3 { numbers[j] += 1 }
^~~~~~~
for j in 0us..3 { numbers[j] += 1 }
^~~~~~~
7:50 note: `numbers` moved into closure environment here
spawn(move || {
for j in 0..3 { numbers[j] += 1 }
for j in 0us..3 { numbers[j] += 1 }
});
6:79 error: cannot assign to immutable dereference (dereference is implicit, due to indexing)
for j in 0..3 { numbers[j] += 1 }
^~~~~~~~~~~~~~~
for j in 0us..3 { numbers[j] += 1 }
^~~~~~~~~~~~~~~
```

It mentions that "numbers moved into closure environment". Because we
Expand Down Expand Up @@ -480,7 +480,7 @@ use std::sync::{Arc,Mutex};
fn main() {
let numbers = Arc::new(Mutex::new(vec![1is, 2, 3]));

for i in 0..3 {
for i in 0us..3 {
let number = numbers.clone();
Thread::spawn(move || {
let mut array = number.lock().unwrap();
Expand Down Expand Up @@ -559,7 +559,7 @@ a vector:
```{rust}
let vec = vec![1, 2, 3];

for i in 0..vec.len() {
for i in 0us..vec.len() {
println!("{}", vec[i]);
}
```
Expand Down