Skip to content

Commit 83a8a56

Browse files
committed
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 `()`
2 parents c4209d1 + 2d1b87c commit 83a8a56

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/doc/guide.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,10 @@ let x = (let y = 5i); // found `let` in ident position
624624
The compiler is telling us here that it was expecting to see the beginning of
625625
an expression, and a `let` can only begin a statement, not an expression.
626626

627-
However, assigning to a variable binding is an expression:
628-
629-
```{rust}
630-
let x;
631-
let y = x = 5i;
632-
```
633-
634-
In this case, we have an assignment expression (`x = 5`) whose value is
635-
being used as part of a `let` declaration statement (`let y = ...`).
627+
Note that assigning to an already-bound variable (e.g. `y = 5i`) is still an
628+
expression, although its value is not particularly useful. Unlike C, where an
629+
assignment evaluates to the assigned value (e.g. `5i` in the previous example),
630+
in Rust the value of an assignment is the unit type `()` (which we'll cover later).
636631

637632
The second kind of statement in Rust is the **expression statement**. Its
638633
purpose is to turn any expression into a statement. In practical terms, Rust's

0 commit comments

Comments
 (0)