Skip to content

Commit 8ab1cd9

Browse files
committed
Add test for for loop maybe initializing binding
1 parent 95923d1 commit 8ab1cd9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn f() -> isize {
2+
let mut x: isize;
3+
for _ in 0..0 { x = 10; }
4+
return x; //~ ERROR E0381
5+
}
6+
7+
fn main() { f(); }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0381]: used binding `x` is possibly-uninitialized
2+
--> $DIR/borrowck-for-loop-uninitialized-binding.rs:4:12
3+
|
4+
LL | let mut x: isize;
5+
| ----- binding declared here but left uninitialized
6+
LL | for _ in 0..0 { x = 10; }
7+
| ---- if the `for` loop runs 0 times, `x` is not initialized
8+
LL | return x;
9+
| ^ `x` used here but it is possibly-uninitialized
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)