diff options
| author | bors <bors@rust-lang.org> | 2014-07-23 06:31:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-23 06:31:11 +0000 |
| commit | 83a8a5647392cd314c8191a5bceff360f0ebb60b (patch) | |
| tree | 3cb8093fe5e00f90a11edba64eec15ecb3f4c02b | |
| parent | c4209d17a0a4fcdb753c4209cecc1ae19cbfcbd6 (diff) | |
| parent | 2d1b87ce33274dff5b5835683531e27e737d6ba4 (diff) | |
| download | rust-83a8a5647392cd314c8191a5bceff360f0ebb60b.tar.gz rust-83a8a5647392cd314c8191a5bceff360f0ebb60b.zip | |
auto merge of #15899 : aochagavia/rust/guide, r=kballard
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 9c52e381462..387841ab3fc 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -624,15 +624,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 |
