title: Store references to same items in different collections: value borrowed after move
body: <p>Let's say I'm trying to create a <code>GameBoard</code> where I have a list/vec of <code>Pieces</code> and references to those pieces on a 2-dimensional grid like this:</p>
  <pre><code>#[derive(Default, Debug)]
  struct Piece;
  
  #[derive(Default, Debug)]
  struct Board&lt;'a&gt; {
      // List of piece instances
      list: Vec&lt;Piece&gt;,
      // References to pieces in the above list but on a grid
      grid: [[Option&lt;&amp;'a Piece&gt;; 8]; 8],
  }
  </code></pre>
  <p>How can I move a <code>Piece</code> to the <code>list</code> but also its reference to the <code>grid</code>? I get borrow after move error. Is this possible to do in Rust?</p>
  <pre><code>fn main() {
      let mut board: Board = Default::default();
      let piece = Piece;
  
      // Move piece to the board.list
      board.list.push(piece);
  
      // Error: borrow of moved value: `piece`
      // value borrowed here after moverustc(E0382)
      board.grid[0][0] = Some(&amp;piece); // Borrow after move error
  }
  </code></pre>
  <p><strong>EDIT + Answer?</strong></p>
  <p>This seems to work:</p>
  <pre><code>fn main() {
      let mut board: Board = Default::default();
      let piece = Piece;
  
      // Move piece to the board.list
      board.list.push(piece);
  
      // This returns an Option&lt;&amp;Piece&gt; so we can then place it in grid
      board.grid[0][0] = board.list.last();
  
      // Looks good!
      assert!(ptr::eq(
          board.list.last().unwrap(),
          board.grid[0][0].unwrap()
      ));
  }
  </code></pre>