Skip to content

Compiler too restrictive for unused variables interacting with closures #29163

Closed
@tbu-

Description

@tbu-

I'd like to write the following code with map:

fn foobar(map: Option<&BTreeMap<u32,u32>>) {
    let temp;
    let map = match map {
        Some(a) => a,
        None => { temp = BTreeMap::new(); &temp }
    }
    // Do something.
}

But the following thing doesn't work:

let temp;
map.unwrap_or_else(|| { temp = BTreeMap::new(); &temp })

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions