Skip to content

Commit

Permalink
Merge pull request #1901 from zanedp/patch-1
Browse files Browse the repository at this point in the history
Fix #1900
  • Loading branch information
marioidival authored Dec 7, 2024
2 parents e1d1f2c + ecd5114 commit 7640633
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/variable_bindings/declare.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 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.
It is possible to declare variable bindings first and initialize them later, but all variable bindings must be initialized before they are used: the compiler forbids use of uninitialized variable bindings, as it would lead to undefined behavior.

It is not common to declare a variable binding and initialize it later in the function.
It is more difficult for a reader to find the initialization when initialization is separated from declaration.
It is common to declare and initialize a variable binding near where the variable will be used.

```rust,editable,ignore,mdbook-runnable
fn main() {
Expand Down Expand Up @@ -30,5 +32,4 @@ fn main() {
}
```

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

0 comments on commit 7640633

Please sign in to comment.