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 a772d98583e..3cb48eed891 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2847,7 +2847,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] ; ``` 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) 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<MutexGuard<T>> ``` -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<T>`, we can't transfer the +guard across thread boundaries, which gives us our error. We can use `Arc<T>` to fix this. Here's the working version: diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index 64d540582a3..0625d649e30 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -50,7 +50,29 @@ 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 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); +``` 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. 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<Output> {