@@ -673,45 +673,35 @@ extern "C" {
673673"## ,
674674
675675E0269 : r##"
676- Functions must eventually return a value of their return type. For example, in
677- the following function:
676+ A returned value was expected but not all control paths return one.
677+
678+ Erroneous code example:
678679
679680```compile_fail,E0269
680681fn abracada_FAIL() -> String {
681682 "this won't work".to_string();
683+ // error: not all control paths return a value
682684}
683685```
684686
685- If the condition is true, the value `x` is returned, but if the condition is
686- false, control exits the `if` block and reaches a place where nothing is being
687- returned. All possible control paths must eventually return a `u8`, which is not
688- happening here.
689-
690- An easy fix for this in a complicated function is to specify a default return
691- value, if possible:
687+ In the previous code, the function is supposed to return a `String`, however,
688+ the code returns nothing (because of the ';'). Another erroneous code would be:
692689
693- ```ignore
694- fn foo(x: u8) -> u8 {
695- if x > 0 {
696- x // alternatively, `return x`
690+ ```compile_fail
691+ fn abracada_FAIL(b: bool) -> u32 {
692+ if b {
693+ 0
694+ } else {
695+ "a" // It fails because an `u32` was expected and something else is
696+ // returned.
697697 }
698- // lots of other if branches
699- 0 // return 0 if all else fails
700698}
701699```
702700
703701It is advisable to find out what the unhandled cases are and check for them,
704702returning an appropriate value or panicking if necessary. Check if you need
705- to remove a semicolon from the last expression, like in this case:
706-
707- ```ignore
708- fn foo(x: u8) -> u8 {
709- inner(2*x + 1);
710- }
711- ```
712-
713- The semicolon discards the return value of `inner`, instead of returning
714- it from `foo`.
703+ to remove a semicolon from the last expression, like in the first erroneous
704+ code example.
715705"## ,
716706
717707E0270 : r##"
0 commit comments