Skip to content

non-mut local variable checking should use typestate #1940

@nikomatsakis

Description

@nikomatsakis

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 uninit(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions