about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-02-19 12:59:35 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2020-02-19 16:09:28 +0100
commit1b342f70dfb999e19026979f28a76952dcc216f4 (patch)
treee6c9537b3ea6505759b08780f617c30c055248a7 /src/librustc_error_codes/error_codes
parentdbef35309d10bed2f09cd55b3e9ea980a58c62aa (diff)
Clean up E0317 explanation
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-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
+};
+```