Skip to content

Fn unboxed closures can incorrectly mutate upvars #17780

Closed
@bkoropoff

Description

@bkoropoff

The following program will write to freed memory:

#![feature(unboxed_closures, overloaded_calls)]

fn main() {
    let mut v = vec![];
    let ref f = |&:| { v.push(0u); v.get_mut(0) };
    let x = (*f)();
    for _ in range(0u, 5) {
        (*f)();
    }
    *x = 42u;
}

Borrowck needs to consider upvars in capture-by-ref, self-by-ref unboxed closures to be aliasable so that mutation and mutable borrows are rejected. I'm working on a patch to do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions