diff options
| author | Adolfo OchagavĂa <aochagavia92@gmail.com> | 2014-07-22 20:12:09 +0200 |
|---|---|---|
| committer | Adolfo OchagavĂa <aochagavia92@gmail.com> | 2014-07-22 20:58:25 +0200 |
| commit | 2d1b87ce33274dff5b5835683531e27e737d6ba4 (patch) | |
| tree | 570c9624861b556067fa45823c6599ac051b5b4e | |
| parent | f15d6d28396e8700b6c3f2704204a2769e710403 (diff) | |
| download | rust-2d1b87ce33274dff5b5835683531e27e737d6ba4.tar.gz rust-2d1b87ce33274dff5b5835683531e27e737d6ba4.zip | |
Remove misleading code example from The Guide
The removed code caused confusion because it is not clear that the type of `y` is actually `()`
| -rw-r--r-- | src/doc/guide.md | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md index 0175817e66a..0807ba8c650 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -684,15 +684,10 @@ let x = (let y = 5i); // found `let` in ident position The compiler is telling us here that it was expecting to see the beginning of an expression, and a `let` can only begin a statement, not an expression. -However, assigning to a variable binding is an expression: - -```{rust} -let x; -let y = x = 5i; -``` - -In this case, we have an assignment expression (`x = 5`) whose value is -being used as part of a `let` declaration statement (`let y = ...`). +Note that assigning to an already-bound variable (e.g. `y = 5i`) is still an +expression, although its value is not particularly useful. Unlike C, where an +assignment evaluates to the assigned value (e.g. `5i` in the previous example), +in Rust the value of an assignment is the unit type `()` (which we'll cover later). The second kind of statement in Rust is the **expression statement**. Its purpose is to turn any expression into a statement. In practical terms, Rust's |
