Declare first

It’s possible to declare variable bindings first, and initialize them later.
However, this form is seldom used, as it may lead to the use of uninitialized
variables.

  1. fn main() {
  2. // Declare a variable binding
  3. let a_binding;
  4. {
  5. let x = 2;
  6. // Initialize the binding
  7. a_binding = x * x;
  8. }
  9. println!("a binding: {}", a_binding);
  10. let another_binding;
  11. // Error! Use of uninitialized binding
  12. println!("another binding: {}", another_binding);
  13. // FIXME ^ Comment out this line
  14. another_binding = 1;
  15. println!("another binding: {}", another_binding);
  16. }

The compiler forbids use of uninitialized variables, as this would lead to
undefined behavior.