Skip to content

Commit 4337e82

Browse files
committed
Add long diagnostic for E0269
1 parent d6be183 commit 4337e82

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/librustc/diagnostics.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,41 @@ fn some_func() {
11211121
```
11221122
"##,
11231123

1124+
E0269: r##"
1125+
Functions must eventually return a value of their return type. For example, in
1126+
the following function
1127+
1128+
```
1129+
fn foo(x: u8) -> u8 {
1130+
if x > 0 {
1131+
x // alternatively, `return x`
1132+
}
1133+
// nothing here
1134+
}
1135+
```
1136+
1137+
if the condition is true, the value `x` is returned, but if the condition is
1138+
false, control exits the `if` block and reaches a place where nothing is being
1139+
returned. All possible control paths must eventually return a `u8`, which is not
1140+
happening here.
1141+
1142+
An easy fix for this in a complicated function is to specify a default return
1143+
value, if possible:
1144+
1145+
```
1146+
fn foo(x: u8) -> u8 {
1147+
if x > 0 {
1148+
x // alternatively, `return x`
1149+
}
1150+
// lots of other if branches
1151+
0 // return 0 if all else fails
1152+
}
1153+
```
1154+
1155+
It is advisable to find out what the unhandled cases are and check for them,
1156+
returning an appropriate value or panicking if necessary.
1157+
"##,
1158+
11241159
E0271: r##"
11251160
This is because of a type mismatch between the associated type of some
11261161
trait (e.g. `T::Bar`, where `T` implements `trait Quux { type Bar; }`)
@@ -1681,7 +1716,6 @@ register_diagnostics! {
16811716
// E0134,
16821717
// E0135,
16831718
E0264, // unknown external lang item
1684-
E0269, // not all control paths return a value
16851719
E0270, // computation may converge in a function marked as diverging
16861720
E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter
16871721
E0273, // rustc_on_unimplemented must have named format arguments

0 commit comments

Comments
 (0)