File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,29 @@ fn main() {
68
68
}
69
69
```
70
70
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
+
71
94
If a value is moved out of a variable, that variable becomes logically
72
95
uninitialized if the type of the value isn't Copy. That is:
73
96
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ discriminant.
47
47
On non-C-like enums, this will inhibit certain optimizations like the null-
48
48
pointer optimization.
49
49
50
- These reprs have no affect on a struct.
50
+ These reprs have no effect on a struct.
51
51
52
52
53
53
You can’t perform that action at this time.
0 commit comments