1

I have the following code (you can try it on play.rust-lang.org):

pub enum InnerStream {
    Root,
    Transaction {
        v: Vec<u32>,
        parent: Box<InnerStream>,
    },
}

impl InnerStream {
    pub fn rollback(self) -> InnerStream {
        match self {
            InnerStream::Transaction { v: _v, parent } => match *parent {
                InnerStream::Root => InnerStream::Root,
                InnerStream::Transaction {
                    v,
                    parent: parent_parent,
                } => InnerStream::Transaction {
                    v,
                    parent: parent_parent,
                },
            },
            InnerStream::Root { .. } => panic!("Cannot rollback root stream."),
        }
    }
}

fn main() {}

(that's an example, not the real one, don't worry if it seems useless)

It looks fine to me, but the borrow-checker gives me the following error:

error[E0382]: use of collaterally moved value: `(parent as InnerStream::Transaction).parent`
  --> src/main.rs:16:29
   |
15 |                     v,
   |                     - value moved here
16 |                     parent: parent_parent,
   |                             ^^^^^^^^^^^^^ value used here after move
   |
   = note: move occurs because the value has type `std::vec::Vec<u32>`, which does not implement the `Copy` trait

What is the cause of this error and how do I fix it?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
  • 1
    I found the first one, but didn't realize it was the same issue as me, and I didn't quite understand your solution. Reading the second one helped me understand, thank you. – Valentin Lorentz Jun 25 '18 at 18:05

0 Answers0