diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2014-10-01 17:14:29 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2014-10-01 17:14:29 -0400 |
| commit | e2357cf41b69c6db57bbf53c63f59376576c72ae (patch) | |
| tree | a62c5e0478f2efbbcb77722a0e1cb72e836e32a8 /src | |
| parent | ee1cbb9c71bfab8500dfabedb35ba63dd1e5b7ff (diff) | |
| download | rust-e2357cf41b69c6db57bbf53c63f59376576c72ae.tar.gz rust-e2357cf41b69c6db57bbf53c63f59376576c72ae.zip | |
Don't compare () to null.
Fixes #17671.
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/guide.md | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md index ac3a58ad39c..30bb48ffccb 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -659,14 +659,12 @@ error: mismatched types: expected `int` but found `()` (expected int but found ( ``` We expected an integer, but we got `()`. `()` is pronounced 'unit', and is a -special type in Rust's type system. `()` is different than `null` in other -languages, because `()` is distinct from other types. For example, in C, `null` -is a valid value for a variable of type `int`. In Rust, `()` is _not_ a valid -value for a variable of type `int`. It's only a valid value for variables of -the type `()`, which aren't very useful. Remember how we said statements don't -return a value? Well, that's the purpose of unit in this case. The semicolon -turns any expression into a statement by throwing away its value and returning -unit instead. +special type in Rust's type system. In Rust, `()` is _not_ a valid value for a +variable of type `int`. It's only a valid value for variables of the type `()`, +which aren't very useful. Remember how we said statements don't return a value? +Well, that's the purpose of unit in this case. The semicolon turns any +expression into a statement by throwing away its value and returning unit +instead. There's one more time in which you won't see a semicolon at the end of a line of Rust code. For that, we'll need our next concept: functions. |
