forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoerce-loop-issue-122561.rs
106 lines (90 loc) · 1.94 KB
/
coerce-loop-issue-122561.rs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Regression test for #122561
fn for_infinite() -> bool {
for i in 0.. {
//~^ ERROR mismatched types
return false;
}
}
fn for_finite() -> String {
for i in 0..5 {
//~^ ERROR mismatched types
return String::from("test");
}
}
fn for_zero_times() -> bool {
for i in 0..0 {
//~^ ERROR mismatched types
return true;
}
}
fn for_never_type() -> ! {
for i in 0..5 {
//~^ ERROR mismatched types
}
}
// Entire function on a single line.
// Tests that we format the suggestion
// correctly in this case
fn for_single_line() -> bool { for i in 0.. { return false; } }
//~^ ERROR mismatched types
// Loop in an anon const in function args
// Tests that we:
// a. deal properly with this complex case
// b. format the suggestion correctly so
// that it's readable
fn for_in_arg(a: &[(); for x in 0..2 {}]) -> bool {
//~^ ERROR mismatched types
true
}
fn while_inifinite() -> bool {
while true {
//~^ ERROR mismatched types
//~| WARN denote infinite loops with `loop { ... }` [while_true]
return true;
}
}
fn while_finite() -> bool {
let mut i = 0;
while i < 3 {
//~^ ERROR mismatched types
i += 1;
return true;
}
}
fn while_zero_times() -> bool {
while false {
//~^ ERROR mismatched types
return true;
}
}
fn while_never_type() -> ! {
while true {
//~^ ERROR mismatched types
//~| WARN denote infinite loops with `loop { ... }` [while_true]
}
}
// No type mismatch error in this case
fn loop_() -> bool {
loop {
return true;
}
}
const C: i32 = {
for i in 0.. {
//~^ ERROR mismatched types
}
};
fn main() {
let _ = [10; {
for i in 0..5 {
//~^ ERROR mismatched types
}
}];
let _ = [10; {
while false {
//~^ ERROR mismatched types
}
}];
let _ = |a: &[(); for x in 0..2 {}]| {};
//~^ ERROR mismatched types
}