From b4e1ce56a33196e657031fb00dafdb4d76763565 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Nikolov Date: Thu, 14 May 2015 17:38:22 +0300 Subject: [PATCH 01/12] trpl-docs: Specify correct type of variable binding --- src/doc/trpl/while-loops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/while-loops.md b/src/doc/trpl/while-loops.md index e71d2033f49ed..a56c546b5516f 100644 --- a/src/doc/trpl/while-loops.md +++ b/src/doc/trpl/while-loops.md @@ -3,7 +3,7 @@ Rust also has a `while` loop. It looks like this: ```{rust} -let mut x = 5; // mut x: u32 +let mut x = 5; // mut x: i32 let mut done = false; // mut done: bool while !done { From acb5e02add66093eef3f47ca5a5bce22ceac7684 Mon Sep 17 00:00:00 2001 From: David Reid Date: Thu, 14 May 2015 08:15:50 -0700 Subject: [PATCH 02/12] Another thread->task fix. --- src/doc/trpl/concurrency.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/concurrency.md b/src/doc/trpl/concurrency.md index d6590e956a841..3c64e0b14de42 100644 --- a/src/doc/trpl/concurrency.md +++ b/src/doc/trpl/concurrency.md @@ -6,7 +6,7 @@ and more cores, yet many programmers aren't prepared to fully utilize them. Rust's memory safety features also apply to its concurrency story too. Even concurrent Rust programs must be memory safe, having no data races. Rust's type -system is up to the thread, and gives you powerful ways to reason about +system is up to the task, and gives you powerful ways to reason about concurrent code at compile time. Before we talk about the concurrency features that come with Rust, it's important From e2bb734ac1457f85c2db821b4e9dbb885059d337 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Thu, 14 May 2015 12:20:33 -0400 Subject: [PATCH 03/12] trpl: punctuation fix --- src/doc/trpl/mutability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/mutability.md b/src/doc/trpl/mutability.md index 674d65974494e..7186c65cdf424 100644 --- a/src/doc/trpl/mutability.md +++ b/src/doc/trpl/mutability.md @@ -35,7 +35,7 @@ let y = &mut x; `y` is an immutable binding to a mutable reference, which means that you can’t bind `y` to something else (`y = &mut z`), but you can mutate the thing that’s -bound to `y`. (`*y = 5`) A subtle distinction. +bound to `y` (`*y = 5`). A subtle distinction. Of course, if you need both: From 785cbe3ac9ae6f79055f87edbbb3128c0db2253b Mon Sep 17 00:00:00 2001 From: Paul Faria Date: Thu, 14 May 2015 13:43:11 -0400 Subject: [PATCH 04/12] I fixed the typo of the value of e in the memory tables. It is a reference to d, and so it should contain the memory location of d. I also fixed the incorrectly formatted tables. --- src/doc/trpl/the-stack-and-the-heap.md | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/doc/trpl/the-stack-and-the-heap.md b/src/doc/trpl/the-stack-and-the-heap.md index f5654d6293991..c47dbd9789354 100644 --- a/src/doc/trpl/the-stack-and-the-heap.md +++ b/src/doc/trpl/the-stack-and-the-heap.md @@ -80,7 +80,7 @@ This memory is kind of like a giant array: addresses start at zero and go up to the final number. So here’s a diagram of our first stack frame: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 0 | x | 42 | We’ve got `x` located at address `0`, with the value `42`. @@ -88,7 +88,7 @@ We’ve got `x` located at address `0`, with the value `42`. When `foo()` is called, a new stack frame is allocated: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 2 | z | 100 | | 1 | y | 5 | | 0 | x | 42 | @@ -107,7 +107,7 @@ value being stored. After `foo()` is over, its frame is deallocated: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 0 | x | 42 | And then, after `main()`, even this last value goes away. Easy! @@ -142,13 +142,13 @@ fn main() { Okay, first, we call `main()`: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 0 | x | 42 | Next up, `main()` calls `foo()`: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 3 | c | 1 | | 2 | b | 100 | | 1 | a | 5 | @@ -157,7 +157,7 @@ Next up, `main()` calls `foo()`: And then `foo()` calls `bar()`: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 4 | i | 6 | | 3 | c | 1 | | 2 | b | 100 | @@ -170,7 +170,7 @@ After `bar()` is over, its frame is deallocated, leaving just `foo()` and `main()`: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 3 | c | 1 | | 2 | b | 100 | | 1 | a | 5 | @@ -179,7 +179,7 @@ After `bar()` is over, its frame is deallocated, leaving just `foo()` and And then `foo()` ends, leaving just `main()` | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 0 | x | 42 | And then we’re done. Getting the hang of it? It’s like piling up dishes: you @@ -206,7 +206,7 @@ fn main() { Here’s what happens in memory when `main()` is called: | Address | Name | Value | -+---------+------+--------+ +|---------|------|--------| | 1 | y | 42 | | 0 | x | ?????? | @@ -218,7 +218,7 @@ it allocates some memory for the heap, and puts `5` there. The memory now looks like this: | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 5 | | ... | ... | ... | | 1 | y | 42 | @@ -243,7 +243,7 @@ layout of a program which has been running for a while now: | Address | Name | Value | -+----------------------+------+----------------------+ +|----------------------|------|----------------------| | 230 | | 5 | | (230) - 1 | | | | (230) - 2 | | | @@ -272,7 +272,7 @@ when it was created. Great! So when `x` goes away, it first frees the memory allocated on the heap: | Address | Name | Value | -+---------+------+--------+ +|---------|------|--------| | 1 | y | 42 | | 0 | x | ?????? | @@ -305,7 +305,7 @@ fn main() { When we enter `main()`, memory looks like this: | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 1 | y | 0 | | 0 | x | 5 | @@ -315,7 +315,7 @@ memory location that `x` lives at, which in this case is `0`. What about when we call `foo()`, passing `y` as an argument? | Address | Name | Value | -+---------+------+-------+ +|---------|------|-------| | 3 | z | 42 | | 2 | i | 0 | | 1 | y | 0 | @@ -367,7 +367,7 @@ fn main() { First, we call `main()`: | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 20 | | ... | ... | ... | | 2 | j | 0 | @@ -380,7 +380,7 @@ value pointing there. Next, at the end of `main()`, `foo()` gets called: | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 20 | | ... | ... | ... | | 5 | z | 4 | @@ -397,7 +397,7 @@ since `j` points at `h`. Next, `foo()` calls `baz()`, passing `z`: | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 20 | | ... | ... | ... | | 7 | g | 100 | @@ -413,7 +413,7 @@ We’ve allocated memory for `f` and `g`. `baz()` is very short, so when it’s over, we get rid of its stack frame: | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 20 | | ... | ... | ... | | 5 | z | 4 | @@ -426,11 +426,11 @@ over, we get rid of its stack frame: Next, `foo()` calls `bar()` with `x` and `z`: | Address | Name | Value | -+----------------------+------+----------------------+ +|----------------------|------|----------------------| | 230 | | 20 | | (230) - 1 | | 5 | | ... | ... | ... | -| 10 | e | 4 | +| 10 | e | 9 | | 9 | d | (230) - 1 | | 8 | c | 5 | | 7 | b | 4 | @@ -449,13 +449,13 @@ case, we set up the variables as usual. At the end of `bar()`, it calls `baz()`: | Address | Name | Value | -+----------------------+------+----------------------+ +|----------------------|------|----------------------| | 230 | | 20 | | (230) - 1 | | 5 | | ... | ... | ... | | 12 | g | 100 | | 11 | f | 4 | -| 10 | e | 4 | +| 10 | e | 9 | | 9 | d | (230) - 1 | | 8 | c | 5 | | 7 | b | 4 | @@ -473,11 +473,11 @@ far. After `baz()` is over, we get rid of `f` and `g`: | Address | Name | Value | -+----------------------+------+----------------------+ +|----------------------|------|----------------------| | 230 | | 20 | | (230) - 1 | | 5 | | ... | ... | ... | -| 10 | e | 4 | +| 10 | e | 9 | | 9 | d | (230) - 1 | | 8 | c | 5 | | 7 | b | 4 | @@ -493,7 +493,7 @@ Next, we return from `bar()`. `d` in this case is a `Box`, so it also frees what it points to: (230) - 1. | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 20 | | ... | ... | ... | | 5 | z | 4 | @@ -506,7 +506,7 @@ what it points to: (230) - 1. And after that, `foo()` returns: | Address | Name | Value | -+-----------------+------+----------------+ +|-----------------|------|----------------| | 230 | | 20 | | ... | ... | ... | | 2 | j | 0 | From dc6eb7839c8b35c997e95b2b94fbf22f9eda9c4c Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Thu, 14 May 2015 14:20:24 -0400 Subject: [PATCH 05/12] trpl: fix link from Structs to Traits --- src/doc/trpl/structs.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/trpl/structs.md b/src/doc/trpl/structs.md index ad7ead9319989..5729aeefbac9c 100644 --- a/src/doc/trpl/structs.md +++ b/src/doc/trpl/structs.md @@ -196,3 +196,5 @@ useful. For instance, a library may ask you to create a structure that implements a certain [trait][trait] to handle events. If you don’t have any data you need to store in the structure, you can just create a unit-like struct. + +[trait]: traits.html From 66c0fe0d3ddec86f7179cb853a8245fe0a34ae8c Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Thu, 14 May 2015 14:35:46 -0400 Subject: [PATCH 06/12] trpl: fix link from Enums to Traits --- src/doc/trpl/enums.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/trpl/enums.md b/src/doc/trpl/enums.md index ad15d19eae143..55de363280026 100644 --- a/src/doc/trpl/enums.md +++ b/src/doc/trpl/enums.md @@ -66,3 +66,4 @@ equality yet, but we’ll find out in the [`traits`][traits] section. [match]: match.html [if-let]: if-let.html +[traits]: traits.html From c147ac42ca81300c545437fb62746378738d7a2d Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Thu, 14 May 2015 14:43:50 -0400 Subject: [PATCH 07/12] trpl: fix link from Match to If Let --- src/doc/trpl/match.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/match.md b/src/doc/trpl/match.md index 2bb2359ba5a01..113e218883b34 100644 --- a/src/doc/trpl/match.md +++ b/src/doc/trpl/match.md @@ -97,4 +97,4 @@ Unlike the previous uses of `match`, you can’t use the normal `if` statement to do this. You can use the [`if let`][if-let] statement, which can be seen as an abbreviated form of `match`. -[if-let][if-let.html] +[if-let]: if-let.html From c8b06891f0633f3cb53ba4e557e0154601c585d1 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Thu, 14 May 2015 14:51:16 -0400 Subject: [PATCH 08/12] trpl: punctuation fix in Patterns --- src/doc/trpl/patterns.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 266c1cafdee57..93df0f19e8eeb 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -66,7 +66,7 @@ match x { } ``` -This prints `something else` +This prints `something else`. # Bindings @@ -152,7 +152,7 @@ match x { } ``` -This prints `Got an int!` +This prints `Got an int!`. # ref and ref mut From 4bdeb311246406b9acb11da03be1981f715abdeb Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Thu, 14 May 2015 20:54:02 +0200 Subject: [PATCH 09/12] Add #[inline] to Borrow::borrow for String. --- src/libcollections/str.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index baef6ba6f01f3..198627ad2fc3a 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -396,6 +396,7 @@ macro_rules! utf8_acc_cont_byte { #[stable(feature = "rust1", since = "1.0.0")] impl Borrow for String { + #[inline] fn borrow(&self) -> &str { &self[..] } } From a1577db825550c5217d797320e1a65781d6412ff Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Thu, 14 May 2015 21:24:09 +0200 Subject: [PATCH 10/12] TRPL: Fix Internal Link --- src/doc/trpl/guessing-game.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index e5702ed163542..e113ce9344976 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -213,12 +213,12 @@ The next part will use this handle to get input from the user: ``` Here, we call the [`read_line()`][read_line] method on our handle. -[Method][method]s are like associated functions, but are only available on a +[Methods][method] are like associated functions, but are only available on a particular instance of a type, rather than the type itself. We’re also passing one argument to `read_line()`: `&mut guess`. [read_line]: ../std/io/struct.Stdin.html#method.read_line -[method]: methods.html +[method]: method-syntax.html Remember how we bound `guess` above? We said it was mutable. However, `read_line` doesn’t take a `String` as an argument: it takes a `&mut String`. From 50fb669241619dbef050f4d27cebc811468f00b5 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Thu, 14 May 2015 15:57:33 -0400 Subject: [PATCH 11/12] s/Iterater/Iterator/ --- src/libstd/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c0d8d8eacf797..171b653f60c17 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -40,7 +40,7 @@ //! [`result`](result/index.html) modules define optional and //! error-handling types, `Option` and `Result`. The //! [`iter`](iter/index.html) module defines Rust's iterator trait, -//! [`Iterater`](iter/trait.Iterator.html), which works with the `for` +//! [`Iterator`](iter/trait.Iterator.html), which works with the `for` //! loop to access collections. //! //! The common container type, `Vec`, a growable vector backed by an array, From 82c7282bec967d7f4431e3ebb9240fa9ce8e4051 Mon Sep 17 00:00:00 2001 From: leunggamciu Date: Fri, 15 May 2015 06:25:01 +0800 Subject: [PATCH 12/12] trpl: Fix missing internal links --- src/doc/trpl/dining-philosophers.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doc/trpl/dining-philosophers.md b/src/doc/trpl/dining-philosophers.md index 81280e8920ca9..87877f02fac60 100644 --- a/src/doc/trpl/dining-philosophers.md +++ b/src/doc/trpl/dining-philosophers.md @@ -73,6 +73,9 @@ a name is all we need. We choose the [`String`][string] type for the name, rather than `&str`. Generally speaking, working with a type which owns its data is easier than working with one that uses references. +[struct]: structs.html +[string]: strings.html + Let’s continue: ```rust