-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #69309 - Dylan-DPC:rollup-gjdqx7l, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #68705 (Add LinkedList::remove()) - #68945 (Stabilize Once::is_completed) - #68978 (Make integer exponentiation methods unstably const) - #69266 (Fix race condition when allocating source files in SourceMap) - #69287 (Clean up E0317 explanation) Failed merges: r? @ghost
- Loading branch information
Showing
8 changed files
with
207 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
This error occurs when an `if` expression without an `else` block is used in a | ||
context where a type other than `()` is expected, for example a `let` | ||
expression: | ||
An `if` expression is missing an `else` block. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0317 | ||
fn main() { | ||
let x = 5; | ||
let a = if x == 5 { 1 }; | ||
} | ||
let x = 5; | ||
let a = if x == 5 { | ||
1 | ||
}; | ||
``` | ||
|
||
This error occurs when an `if` expression without an `else` block is used in a | ||
context where a type other than `()` is expected. In the previous code example, | ||
the `let` expression was expecting a value but since there was no `else`, no | ||
value was returned. | ||
|
||
An `if` expression without an `else` block has the type `()`, so this is a type | ||
error. To resolve it, add an `else` block having the same type as the `if` | ||
block. | ||
|
||
So to fix the previous code example: | ||
|
||
``` | ||
let x = 5; | ||
let a = if x == 5 { | ||
1 | ||
} else { | ||
2 | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.