Skip to content

rvalue lifetime too short when equivalent match works #7660

Closed
@alexcrichton

Description

@alexcrichton

Sometimes the lifetime of an expression is considered too short when it's an rvalue, but the equivalent code using match works just fine:

use std::hashmap::HashMap;
struct A(int, int);
fn main() {
    let m: HashMap<int, A> = HashMap::new();

    let A(ref _a, ref _b) = *m.get(&1); // compiler error!
    let (a, b) = match *m.get(&1) { A(ref _a, ref _b) => (_a, _b) }; // ok
}

This may be related to #3511, but this seems like it may just be a bug in lifetimes somewhere?

ping @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions