fn cartesian_product(scale: &mut (u32, u32)) -> Vec<(u32, u32)> { (0..5) .flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1))) .collect() } // error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function // --> src/main.rs:7:34 // | // 7 | .flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1))) // | ^^^ - `a` is borrowed here // | | // | may outlive borrowed value `a` // | // note: closure is returned here // --> src/main.rs:7:23 // | // 7 | .flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1))) // | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword // | // 7 | .flat_map(|a| (0..5).map(move |b| (a * scale.0, b * scale.1))) // | ^^^^^^^^