From 9b873faef51a2178f48178d1003f291dac142924 Mon Sep 17 00:00:00 2001 From: Alan Cutter Date: Sun, 1 Mar 2015 15:37:40 +1100 Subject: [PATCH 1/8] Fix missed doc grammar rule rename from vec_elems to array_elems --- src/doc/grammar.md | 2 +- src/doc/reference.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index d7a29ea5309..68ca1cb7217 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -514,7 +514,7 @@ field_expr : expr '.' ident ; ### Array expressions ```antlr -array_expr : '[' "mut" ? vec_elems? ']' ; +array_expr : '[' "mut" ? array_elems? ']' ; array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ; ``` diff --git a/src/doc/reference.md b/src/doc/reference.md index 2f047d2c173..a24db2f247f 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2821,7 +2821,7 @@ automatically dereferenced to make the field access possible. ### Array expressions ```{.ebnf .gram} -array_expr : '[' "mut" ? vec_elems? ']' ; +array_expr : '[' "mut" ? array_elems? ']' ; array_elems : [expr [',' expr]*] | [expr ';' expr] ; ``` From e56fcbcd9959f3bbc0ff2c3f796dedc72c28c865 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 8 Mar 2015 09:15:06 -0400 Subject: [PATCH 2/8] Remove reference to NoSend in concurrency chapter of the book Fixes #23052 --- src/doc/trpl/concurrency.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/doc/trpl/concurrency.md b/src/doc/trpl/concurrency.md index 842957bd601..9b6d6ca67f6 100644 --- a/src/doc/trpl/concurrency.md +++ b/src/doc/trpl/concurrency.md @@ -223,15 +223,8 @@ method which has this signature: fn lock(&self) -> LockResult> ``` -If we [look at the code for MutexGuard](https://github.com/rust-lang/rust/blob/ca4b9674c26c1de07a2042cb68e6a062d7184cef/src/libstd/sync/mutex.rs#L172), we'll see -this: - -```ignore -__marker: marker::NoSend, -``` - -Because our guard is `NoSend`, it's not `Send`. Which means we can't actually -transfer the guard across thread boundaries, which gives us our error. +Because `Send` is not implemented for `MutexGuard`, we can't transfer the +guard across thread boundaries, which gives us our error. We can use `Arc` to fix this. Here's the working version: From ce223a62f1da97327ae2ef3e5e59095a639bc20f Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 8 Mar 2015 09:23:44 -0400 Subject: [PATCH 3/8] Mention deref coercions in the String guide. Fixes #22637 --- src/doc/trpl/more-strings.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md index a2a558094e1..6567cd448f9 100644 --- a/src/doc/trpl/more-strings.md +++ b/src/doc/trpl/more-strings.md @@ -278,7 +278,18 @@ This will print: Many more bytes than graphemes! -# Other Documentation +# `Deref` coercions -* [the `&str` API documentation](../std/str/index.html) -* [the `String` API documentation](../std/string/index.html) +References to `String`s will automatically coerce into `&str`s. Like this: + +``` +fn hello(s: &str) { + println!("Hello, {}!", s); +} + +let slice = "Steve"; +let string = "Steve".to_string(); + +hello(slice); +hello(&string); +``` From 5b0acb5846485846698d2d352b85837e3b4dfef9 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 8 Mar 2015 09:29:47 -0400 Subject: [PATCH 4/8] remove 'generally' to reduce confusion Fixes #22610 --- src/doc/trpl/pointers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/pointers.md b/src/doc/trpl/pointers.md index e56706500a0..930a40c5050 100644 --- a/src/doc/trpl/pointers.md +++ b/src/doc/trpl/pointers.md @@ -634,8 +634,8 @@ use-case for boxes. ### Returning data This is important enough to have its own section entirely. The TL;DR is this: -you don't generally want to return pointers, even when you might in a language -like C or C++. +you don't want to return pointers, even when you might in a language like C or +C++. See [Returning Pointers](#returning-pointers) below for more. From d65064da349f1f7182180549628fb0ee650771b7 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 8 Mar 2015 09:34:03 -0400 Subject: [PATCH 5/8] Move 'more strings' after ownership Fixes #22553 --- src/doc/trpl/SUMMARY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/SUMMARY.md b/src/doc/trpl/SUMMARY.md index d57aff7f4f4..c65389287fb 100644 --- a/src/doc/trpl/SUMMARY.md +++ b/src/doc/trpl/SUMMARY.md @@ -16,11 +16,11 @@ * [Standard Input](standard-input.md) * [Guessing Game](guessing-game.md) * [II: Intermediate Rust](intermediate.md) - * [More Strings](more-strings.md) * [Crates and Modules](crates-and-modules.md) * [Testing](testing.md) * [Pointers](pointers.md) * [Ownership](ownership.md) + * [More Strings](more-strings.md) * [Patterns](patterns.md) * [Method Syntax](method-syntax.md) * [Closures](closures.md) From 044b3bf2d74de0b265e76fa5d0c735cdb15df690 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 8 Mar 2015 10:49:13 -0400 Subject: [PATCH 6/8] Add examples of all three syntaxes in method syntax chapter of trpl Fixes #18787 --- src/doc/trpl/method-syntax.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index 64d540582a3..b814ff16abb 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -50,7 +50,28 @@ You can think of this first parameter as being the `x` in `x.foo()`. The three variants correspond to the three kinds of thing `x` could be: `self` if it's just a value on the stack, `&self` if it's a reference, and `&mut self` if it's a mutable reference. We should default to using `&self`, as it's the most -common. +common. Here's an example of all three variants: + +```rust +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +impl Circle { + fn reference(&self) { + println!("taking self by reference!"); + } + + fn mutable_reference(&mut self) { + println!("taking self by mutable reference!"); + } + + fn takes_ownership(self) { + println!("taking ownership of self!"); + } +``` Finally, as you may remember, the value of the area of a circle is `π*r²`. Because we took the `&self` parameter to `area`, we can use it just like any From 6c6c23f9dfc98ad0a6ebc596de197aedd3a79889 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 8 Mar 2015 12:07:58 -0400 Subject: [PATCH 7/8] Small fixes to example to be more idiomatic --- src/libstd/process.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 79028f49e68..d4392a0740a 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -264,7 +264,7 @@ impl Command { /// By default, stdin, stdout and stderr are captured (and used to /// provide the resulting output). /// - /// # Example + /// # Examples /// /// ``` /// # #![feature(process)] @@ -275,8 +275,8 @@ impl Command { /// }); /// /// println!("status: {}", output.status); - /// println!("stdout: {}", String::from_utf8_lossy(output.stdout.as_slice())); - /// println!("stderr: {}", String::from_utf8_lossy(output.stderr.as_slice())); + /// println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + /// println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn output(&mut self) -> io::Result { From 3797827460bde2044acb17415a51c0351b5d2dec Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 9 Mar 2015 10:16:34 +0530 Subject: [PATCH 8/8] Fix doctest (fixup #23188) --- src/doc/trpl/method-syntax.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index b814ff16abb..0625d649e30 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -71,6 +71,7 @@ impl Circle { fn takes_ownership(self) { println!("taking ownership of self!"); } +} ``` Finally, as you may remember, the value of the area of a circle is `π*r²`.