]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0381.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0381.md
1 It is not allowed to use or capture an uninitialized variable.
2
3 Erroneous code example:
4
5 ```compile_fail,E0381
6 fn main() {
7     let x: i32;
8     let y = x; // error, use of possibly-uninitialized variable
9 }
10 ```
11
12 To fix this, ensure that any declared variables are initialized before being
13 used. Example:
14
15 ```
16 fn main() {
17     let x: i32 = 0;
18     let y = x; // ok!
19 }
20 ```