Skip to content

Commit 7e4b950

Browse files
---
yaml --- r: 223087 b: refs/heads/auto c: 74787b9 h: refs/heads/master i: 223085: fe04775 223083: 1a91afe 223079: 4c59761 223071: 37ebf43 v: v3
1 parent be43fd9 commit 7e4b950

File tree

11 files changed

+238
-225
lines changed

11 files changed

+238
-225
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 2a309b7f55bd68aa76aada01f5c9503f02eb2e4a
11+
refs/heads/auto: 74787b98badd43eb069349e30d56b28f8f13be0f
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ sudo: false
2020
before_script:
2121
- ./configure --enable-ccache
2222
script:
23-
- make tidy check -j4
23+
- make tidy
24+
- make rustc-stage1 -j4
2425

2526
env:
2627
- CXX=/usr/bin/g++-4.7

branches/auto/src/doc/trpl/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
* [Primitive Types](primitive-types.md)
2727
* [Comments](comments.md)
2828
* [if](if.md)
29-
* [Loops](loops.md)
29+
* [for loops](for-loops.md)
30+
* [while loops](while-loops.md)
3031
* [Ownership](ownership.md)
3132
* [References and Borrowing](references-and-borrowing.md)
3233
* [Lifetimes](lifetimes.md)

branches/auto/src/doc/trpl/choosing-your-guarantees.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ scope.
308308

309309
Both of these provide safe shared mutability across threads, however they are prone to deadlocks.
310310
Some level of additional protocol safety can be obtained via the type system.
311-
312311
#### Costs
313312

314313
These use internal atomic-like types to maintain the locks, which are pretty costly (they can block
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
% for Loops
2+
3+
The `for` loop is used to loop a particular number of times. Rust’s `for` loops
4+
work a bit differently than in other systems languages, however. Rust’s `for`
5+
loop doesn’t look like this “C-style” `for` loop:
6+
7+
```c
8+
for (x = 0; x < 10; x++) {
9+
printf( "%d\n", x );
10+
}
11+
```
12+
13+
Instead, it looks like this:
14+
15+
```rust
16+
for x in 0..10 {
17+
println!("{}", x); // x: i32
18+
}
19+
```
20+
21+
In slightly more abstract terms,
22+
23+
```ignore
24+
for var in expression {
25+
code
26+
}
27+
```
28+
29+
The expression is an [iterator][iterator]. The iterator gives back a series of
30+
elements. Each element is one iteration of the loop. That value is then bound
31+
to the name `var`, which is valid for the loop body. Once the body is over, the
32+
next value is fetched from the iterator, and we loop another time. When there
33+
are no more values, the `for` loop is over.
34+
35+
[iterator]: iterators.html
36+
37+
In our example, `0..10` is an expression that takes a start and an end position,
38+
and gives an iterator over those values. The upper bound is exclusive, though,
39+
so our loop will print `0` through `9`, not `10`.
40+
41+
Rust does not have the “C-style” `for` loop on purpose. Manually controlling
42+
each element of the loop is complicated and error prone, even for experienced C
43+
developers.
44+
45+
# Enumerate
46+
47+
When you need to keep track of how many times you already looped, you can use the `.enumerate()` function.
48+
49+
## On ranges:
50+
51+
```rust
52+
for (i,j) in (5..10).enumerate() {
53+
println!("i = {} and j = {}", i, j);
54+
}
55+
```
56+
57+
Outputs:
58+
59+
```text
60+
i = 0 and j = 5
61+
i = 1 and j = 6
62+
i = 2 and j = 7
63+
i = 3 and j = 8
64+
i = 4 and j = 9
65+
```
66+
67+
Don't forget to add the parentheses around the range.
68+
69+
## On iterators:
70+
71+
```rust
72+
# let lines = "hello\nworld".lines();
73+
for (linenumber, line) in lines.enumerate() {
74+
println!("{}: {}", linenumber, line);
75+
}
76+
```
77+
78+
Outputs:
79+
80+
```text
81+
0: Content of line one
82+
1: Content of line two
83+
2: Content of line tree
84+
3: Content of line four
85+
```

branches/auto/src/doc/trpl/loops.md

Lines changed: 0 additions & 209 deletions
This file was deleted.

branches/auto/src/doc/trpl/the-stack-and-the-heap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ frame. But before we can show what happens when `foo()` is called, we need to
7373
visualize what’s going on with memory. Your operating system presents a view of
7474
memory to your program that’s pretty simple: a huge list of addresses, from 0
7575
to a large number, representing how much RAM your computer has. For example, if
76-
you have a gigabyte of RAM, your addresses go from `0` to `1,073,741,823`. That
76+
you have a gigabyte of RAM, your addresses go from `0` to `1,073,741,824`. That
7777
number comes from 2<sup>30</sup>, the number of bytes in a gigabyte.
7878

7979
This memory is kind of like a giant array: addresses start at zero and go
@@ -551,7 +551,7 @@ is a great introduction.
551551

552552
[wilson]: http://www.cs.northwestern.edu/~pdinda/icsclass/doc/dsa.pdf
553553

554-
## Semantic impact
554+
## Semantic impact
555555

556556
Stack-allocation impacts the Rust language itself, and thus the developer’s
557557
mental model. The LIFO semantics is what drives how the Rust language handles

0 commit comments

Comments
 (0)