about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-20 10:49:14 +0100
committerGitHub <noreply@github.com>2020-02-20 10:49:14 +0100
commit941ce1a557639e23ccb8cf2610aa8341190dbdfa (patch)
treef6bf5af610abed3554aad342dda2f11a6ecba625
parent5d285dcb220b58a8bdef7304f54bc0d8f184393c (diff)
parent1b342f70dfb999e19026979f28a76952dcc216f4 (diff)
downloadrust-941ce1a557639e23ccb8cf2610aa8341190dbdfa.tar.gz
rust-941ce1a557639e23ccb8cf2610aa8341190dbdfa.zip
Rollup merge of #69287 - GuillaumeGomez:clean-e0317, r=Dylan-DPC
Clean up E0317 explanation

r? @Dylan-DPC
-rw-r--r--src/librustc_error_codes/error_codes/E0317.md30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/librustc_error_codes/error_codes/E0317.md b/src/librustc_error_codes/error_codes/E0317.md
index e31a2b56be3..230911c2086 100644
--- a/src/librustc_error_codes/error_codes/E0317.md
+++ b/src/librustc_error_codes/error_codes/E0317.md
@@ -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
+};
+```