diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-07-19 19:13:25 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-07-23 12:49:26 +0530 |
| commit | 4337e822fb043e3e3abd085ca6483f15f11d913a (patch) | |
| tree | 6b4f1a535d06917f5df9fc4f1f26ed145ad1ad54 | |
| parent | d6be183af1d76a2716f1a3dc00b3ad3a2b746b37 (diff) | |
Add long diagnostic for E0269
| -rw-r--r-- | src/librustc/diagnostics.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 0d949c98023..969293800f1 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1121,6 +1121,41 @@ fn some_func() { ``` "##, +E0269: r##" +Functions must eventually return a value of their return type. For example, in +the following function + +``` +fn foo(x: u8) -> u8 { + if x > 0 { + x // alternatively, `return x` + } + // nothing here +} +``` + +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: + +``` +fn foo(x: u8) -> u8 { + if x > 0 { + x // alternatively, `return x` + } + // 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. +"##, + E0271: r##" This is because of a type mismatch between the associated type of some trait (e.g. `T::Bar`, where `T` implements `trait Quux { type Bar; }`) @@ -1681,7 +1716,6 @@ register_diagnostics! { // E0134, // E0135, E0264, // unknown external lang item - E0269, // not all control paths return a value E0270, // computation may converge in a function marked as diverging E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter E0273, // rustc_on_unimplemented must have named format arguments |
