Getting "Use of moved value" in a loop

Viewed 39

I'm making Tic-tac-toe in Rust. I want to count the amount of cells in a line, when the player is moving. Like -- x --. So I call count_result two times with the same dx and dy (that's why I pass dx and dy by reference). But here's the problem. My linter in IntelliJ IDEA complains that I use moved value. The compiler compiles without any warnings. What is the problem? Can you help me?

IntelliJ IDEA screenshot

Just to clarify - game_data.board is [[Option<Cell>; 3]; 3]

struct Data {
    board: [[Option<Cell>; 3]; 3],
}
fn count_result(game_data: &Data, point: &Point, cell: &Cell, dx: &isize, dy: &isize) -> isize {
    let mut count: isize = 0;
    let point = (*point).clone();
    let mut x = point.x;
    let mut y = point.y;
    while (x + dx < 3 && x + dx >= 0) && (y + dy >= 0 && y + dy < 3) {
        x += 1;
        y += 1;
        if game_data.board[x as usize][y as usize] == Some(*cell) {
             count += 1;
        } else {
             break;
        }
    }
    count
}

Here is another example of the same problem. game_data: &mut Data

IntelliJ IDEA screenshot

0 Answers
Related