1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-20 06:21:09 +02:00

Update if.md (#2286)

The original phrasing may imply that you have to always terminated a
`if` expression with `;`. But the real reason that we have to do that is
because we are using it in a `let` statement here, and `let` statement
has to be terminated by `;`

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
This commit is contained in:
Jason Lin 2024-08-20 18:15:39 +10:00 committed by GitHub
parent 127202d591
commit 4012e2a883
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,8 +38,8 @@ Because `if` is an expression and must have a particular type, both of its
branch blocks must have the same type. Show what happens if you add `;` after
`"small"` in the second example.
When `if` is used in an expression, the expression must have a `;` to separate
it from the next statement. Remove the `;` before `println!` to see the compiler
error.
An `if` expression should be used in the same way as the other expressions. For
example, when it is used in a `let` statement, the statement must be terminated
with a `;` as well. Remove the `;` before `println!` to see the compiler error.
</details>