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

can't move out nested boxes #16227

Closed
goffrie opened this issue Aug 3, 2014 · 2 comments
Closed

can't move out nested boxes #16227

goffrie opened this issue Aug 3, 2014 · 2 comments

Comments

@goffrie
Copy link
Contributor

goffrie commented Aug 3, 2014

The following code seems like it should work, but it produces a cryptic error:

fn main() {
    let f = box Some((box 1i, box 2i));
    let g = match f { box Some((a, b)) => (*b, *a), _ => (0,0) };
    println!("{}", g);
}
<anon>:3:36: 3:37 error: use of partially moved value: `f#0#1`
<anon>:3     let g = match f { box Some((a, b)) => (*b, *a), _ => (0,0) };
                                            ^
<anon>:3:33: 3:34 note: `f#0#0` moved here because it has type `Box<int>`, which is moved by default (use `ref` to override)
<anon>:3     let g = match f { box Some((a, b)) => (*b, *a), _ => (0,0) };
                                         ^
error: aborting due to previous error

However, removing the outermost box works:

fn main() {
    let f = Some((box 1i, box 2i));
    let g = match f { Some((a, b)) => (*b, *a), _ => (0,0) };
    println!("{}", g); // => (2, 1)
}

Alternatively, matching on an rvalue also works:

fn main() {
    let f = box Some((box 1i, box 2i));
    let g = match f.clone() { box Some((a, b)) => (*b, *a), _ => (0,0) };
    println!("{}", g); // => (2, 1)
}
@alexcrichton
Copy link
Member

This may be a dupe of #16223, but I'm not sure. cc @zwarich

@goffrie
Copy link
Contributor Author

goffrie commented Aug 4, 2014

Oops, yeah, I'm pretty sure this is a dupe.

@goffrie goffrie closed this as completed Aug 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants