Skip to content

Illegal mutable borrow incorrectly allowed #14036

Closed
@samyatchmenoff

Description

@samyatchmenoff

Example:

fn main() {
    let mut x = Some(~1);
    let mut p: proc(&mut Option<~int>) = proc(_) {};
    match x {
        Some(ref y) => {
            p = proc(z: &mut Option<~int>) {
                *z = None;
                println!("{}", y);
            }
        }
        None => {}
    }
    p(&mut x);
}

The last statement p(&mut x) is mutably borrowing x but x is already borrowed (or rather should be) by the proc.

The result is a program that compiles fine but segfaults when run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions