blob: 9c8685a77127b2ed03ac39958dbd8bc1b3070b97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
error[E0308]: mismatched types
--> $DIR/issue-100285.rs:2:5
|
LL | fn foo(n: i32) -> i32 {
| --- expected `i32` because of return type
LL | / for i in 0..0 {
LL | | if n < 0 {
LL | | return i;
LL | | } else if n < 10 {
... |
LL | |
LL | | }
| |_____^ expected `i32`, found `()`
|
note: the function expects a value to always be returned, but loops might run zero times
--> $DIR/issue-100285.rs:2:5
|
LL | for i in 0..0 {
| ^^^^^^^^^^^^^ this might have zero elements to iterate on
LL | if n < 0 {
LL | return i;
| -------- if the loop doesn't execute, this value would never get returned
LL | } else if n < 10 {
LL | return 1;
| -------- if the loop doesn't execute, this value would never get returned
LL | } else if n < 20 {
LL | return 2;
| -------- if the loop doesn't execute, this value would never get returned
= note: if the loop doesn't execute, 3 other values would never get returned
help: return a value for the case when the loop has zero elements to iterate on
|
LL ~ }
LL ~ /* `i32` value */
|
help: otherwise consider changing the return type to account for that possibility
|
LL ~ fn foo(n: i32) -> Option<i32> {
LL | for i in 0..0 {
LL | if n < 0 {
LL ~ return Some(i);
LL | } else if n < 10 {
LL ~ return Some(1);
LL | } else if n < 20 {
LL ~ return Some(2);
LL | } else if n < 30 {
LL ~ return Some(3);
LL | } else if n < 40 {
LL ~ return Some(4);
LL | } else {
LL ~ return Some(5);
LL | }
LL |
LL ~ }
LL ~ None
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
|