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

"Collaterally moved value" error for something that looks fine to me #19828

Closed
sellibitze opened this issue Dec 14, 2014 · 2 comments
Closed
Labels
A-typesystem Area: The type system

Comments

@sellibitze
Copy link
Contributor

The code

pub type MoveList<M> = Option<Box<MoveNode<M>>>;

pub struct MoveNode<M> {
    m: M,
    n: MoveList<M>
}

pub fn pop_front<M>(ml: MoveList<M>) -> (Option<M>, MoveList<M>) {
    match ml {
        None => (None, None),
        Some(box MoveNode { m, n }) => (Some(m), n)
    }
}

produces the error message “error: use of collaterally moved value” pointing to the second match arm. See http://is.gd/kBotGl -- tested on 2015-01-16 again: same result.

But when the destructuring is split in two parts, it works:

pub fn pop_front<M>(ml: MoveList<M>) -> (Option<M>, MoveList<M>) {
    match ml {
        None => (None, None),
        Some(box ml) => {
            let MoveNode {m, n} = ml;
            (Some(m), n)
        }
    }
}

This looks like a compiler bug to me.

@pythonesque
Copy link
Contributor

You can also make it match properly by calling take() on ml:

pub fn pop_front<M>(mut ml: MoveList<M>) -> (Option<M>, MoveList<M>) {
    match ml.take() {
        None => (None, None),
        Some(box MoveNode {m, n }) => (Some(m), n)
    }
}

@kmcallister kmcallister added the A-typesystem Area: The type system label Jan 16, 2015
@alexcrichton
Copy link
Member

Box patterns have since been feature gated, and other usability concerns I believe are covered by #16223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

4 participants