mozilla/rust — Issue #1940: non-mut local variable checking should use typestate
Author: nikomatsakis
Created: 2012-03-07 18:35:38+00:00
State: open
Labels: A-typestate

Right now, I have a simple rule that non-mutable local variables cannot be assigned ever. This is too simplistic. We should track an `uninit` predicate for each local variable and only allow assignment to `x` if `unint(x)` holds. (Note that it is possible to be in a state where neither `init(x)` nor `uninit(x)` holds, if `x` is initialized on some paths but not others)

I tried delving into the type state module to make these changes but they proved somewhat invasive. Currently predicates are indexed by `def_id`, for example, but this will have to change as there would be multiple predicates associated with the `def_id` of each local variable. So I decided to just leave my simple-minded check and file an issue.