about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-06-28 16:05:15 +0200
committerGitHub <noreply@github.com>2016-06-28 16:05:15 +0200
commitb34f6e724542aff2424c4f0864a7eb4ca1062a6c (patch)
tree16677ea1828d1f14f772c2b1732a14a0940b313c
parentb765edf440ae7ecb8a5026d101767a331012f1e9 (diff)
parent988ca464e48fd0a3bc1d162fc97eb34499ca7500 (diff)
downloadrust-b34f6e724542aff2424c4f0864a7eb4ca1062a6c.tar.gz
rust-b34f6e724542aff2424c4f0864a7eb4ca1062a6c.zip
Rollup merge of #34471 - GuillaumeGomez:fix_expl, r=steveklabnik
Fix E0269 error explanation

r? @steveklabnik
-rw-r--r--src/librustc/diagnostics.rs40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index 538613c7fac..9040e4bf8db 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -673,45 +673,35 @@ extern "C" {
 "##,
 
 E0269: r##"
-Functions must eventually return a value of their return type. For example, in
-the following function:
+A returned value was expected but not all control paths return one.
+
+Erroneous code example:
 
 ```compile_fail,E0269
 fn abracada_FAIL() -> String {
     "this won't work".to_string();
+    // error: not all control paths return a value
 }
 ```
 
-If the condition is true, the value `x` is returned, but if the condition is
-false, control exits the `if` block and reaches a place where nothing is being
-returned. All possible control paths must eventually return a `u8`, which is not
-happening here.
-
-An easy fix for this in a complicated function is to specify a default return
-value, if possible:
+In the previous code, the function is supposed to return a `String`, however,
+the code returns nothing (because of the ';'). Another erroneous code would be:
 
-```ignore
-fn foo(x: u8) -> u8 {
-    if x > 0 {
-        x // alternatively, `return x`
+```compile_fail
+fn abracada_FAIL(b: bool) -> u32 {
+    if b {
+        0
+    } else {
+        "a" // It fails because an `u32` was expected and something else is
+            // returned.
     }
-    // lots of other if branches
-    0 // return 0 if all else fails
 }
 ```
 
 It is advisable to find out what the unhandled cases are and check for them,
 returning an appropriate value or panicking if necessary. Check if you need
-to remove a semicolon from the last expression, like in this case:
-
-```ignore
-fn foo(x: u8) -> u8 {
-    inner(2*x + 1);
-}
-```
-
-The semicolon discards the return value of `inner`, instead of returning
-it from `foo`.
+to remove a semicolon from the last expression, like in the first erroneous
+code example.
 "##,
 
 E0270: r##"