1

I got the following error

error[E0507]: cannot move out of `piece.source` which is behind a shared reference
  --> src/buffer.rs:77:37
   |
77 | ...                   source: piece.source,
   |                               ^^^^^^^^^^^^ move occurs because `piece.source` has type `buffer::PieceSource`, which does not implement the `Copy` trait

error[E0507]: cannot move out of `piece.source` which is behind a shared reference
  --> src/buffer.rs:84:37
   |
84 | ...                   source: piece.source,
   |                               ^^^^^^^^^^^^ move occurs because `piece.source` has type `buffer::PieceSource`, which does not implement the `Copy` trait

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0507`.

and I don't understand what the compiler means by "move out".

Pablo Tato Ramos
  • 409
  • 4
  • 18
  • How I read it, `move out of` means `move from`. – rodrigo Mar 04 '20 at 13:31
  • @rodrigo I mean in terms of semantics in the program. – Pablo Tato Ramos Mar 04 '20 at 13:33
  • @trentcl Does it? Does "move out" mean the same as "move"? – Pablo Tato Ramos Mar 04 '20 at 13:43
  • see also: https://stackoverflow.com/questions/28158738/cannot-move-out-of-borrowed-content-cannot-move-out-of-behind-a-shared-referen – Ömer Erden Mar 04 '20 at 13:48
  • 1
    @Pablo If you stand up *out of your chair*, are you still standing up? Or is it not standing up, but *standing up out*? – trent Mar 04 '20 at 13:52
  • @trentcl Is this a riddle? – Pablo Tato Ramos Mar 04 '20 at 13:53
  • @trentcl My answer is: I don't know – Pablo Tato Ramos Mar 04 '20 at 13:53
  • 1
    Ok, sorry, maybe that was a flippant response: I'm just trying to understand the confusion between "move" and "move out". To me, if you understand *move semantics*, which the linked question answers, I don't think there is any ambiguity about what the error message says, so I don't understand what there is to be confused about. Moving is inherently directional; there's a *from* and a *to* -- not only in Rust, but in English in general... "out of `piece.source`" is just a prepositional phrase that describes the *from* part. – trent Mar 04 '20 at 14:01
  • @trentcl Ok, thanks. My first reaction was that the out meant a different thing, or else it would just say move. I don't picture an "inside" or an "outside" of an assignment. – Pablo Tato Ramos Mar 04 '20 at 14:06
  • @PabloTatoRamos Those terms begin to make sense when the assignment implements move. To make an analogy with the real world: if you take a page out of a book, the book will no longer be complete. And if the book doesn't belong to you (it's borrowed), you're not allowed to leave it in an invalid state. – user4815162342 Mar 04 '20 at 19:02

0 Answers0