Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rvalue lifetime too short when equivalent match works #7660

Closed
alexcrichton opened this issue Jul 9, 2013 · 8 comments
Closed

rvalue lifetime too short when equivalent match works #7660

alexcrichton opened this issue Jul 9, 2013 · 8 comments
Labels
A-lifetimes Area: lifetime related

Comments

@alexcrichton
Copy link
Member

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

@alexcrichton
Copy link
Member Author

Nominating for production-ready: after niko's patches about ref bindings in irrefut patterns landed, this form of destructuring assignment is almost there! It's really painful to use match all over the place when the majority of the surrounding code uses owned pointers.

@alexcrichton
Copy link
Member Author

This is also a continuation of the bug in #4653 (the llvm assertions of which were very recently fixed).

@nikomatsakis
Copy link
Contributor

I'll take a look. This does indeed look like regionck is failing to propagate the necessary constraints.

@thestinger
Copy link
Contributor

This is still an issue.

@catamorphism
Copy link
Contributor

Accepted for production-ready

@flaper87
Copy link
Contributor

cc @flaper87

@nikomatsakis
Copy link
Contributor

I...expect this may work now but I'm not entirely sure.

@flaper87
Copy link
Contributor

I does compile now, I'll submit a test case for it

flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 28, 2021
Fix derivable impl false positives

fix rust-lang#7654
fix rust-lang#7655

changelog: none (not released)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related
Projects
None yet
Development

No branches or pull requests

5 participants