Skip to content

Commit 13b2605

Browse files
committed
fixup and cool example for checked-uninit
1 parent c97673c commit 13b2605

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/doc/tarpl/checked-uninit.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ fn main() {
6868
}
6969
```
7070

71+
Of course, while the analysis doesn't consider actual values, it does
72+
have a relatively sophisticated understanding of dependencies and control
73+
flow. For instance, this works:
74+
75+
```rust
76+
let x: i32;
77+
78+
loop {
79+
// Rust doesn't understand that this branch will be taken unconditionally,
80+
// because it relies on actual values.
81+
if true {
82+
// But it does understand that it will only be taken once because
83+
// we *do* unconditionally break out of it. Therefore `x` doesn't
84+
// need to be marked as mutable.
85+
x = 0;
86+
break;
87+
}
88+
}
89+
// It also knows that it's impossible to get here without reaching the break.
90+
// And therefore that `x` must be initialized here!
91+
println!("{}", x);
92+
```
93+
7194
If a value is moved out of a variable, that variable becomes logically
7295
uninitialized if the type of the value isn't Copy. That is:
7396

src/doc/tarpl/other-reprs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ discriminant.
4747
On non-C-like enums, this will inhibit certain optimizations like the null-
4848
pointer optimization.
4949

50-
These reprs have no affect on a struct.
50+
These reprs have no effect on a struct.
5151

5252

5353

0 commit comments

Comments
 (0)