Skip to content

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

@sellibitze

Description

@sellibitze

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions