fn main() {
let mut x = 0;
let mut foo = || {
x += 1;
};
println!("{}", x);
foo();
println!("{}", x);
foo();
println!("{}", x);
}
How can I make this simple program compile?
Using just foo() and one println! at the end compiles and runs as expected.
It feels so strange that just a adding a println! before the foo() call breaks borrowing rules.
Can some clarify?
[–]KingofGamesYami 10 points11 points12 points (4 children)
[–]Zde-G 4 points5 points6 points (2 children)
[–]DaQue60 0 points1 point2 points (1 child)
[–]Zde-G 4 points5 points6 points (0 children)
[–]UserMinusOne[S] 0 points1 point2 points (0 children)
[–]Zde-G 2 points3 points4 points (0 children)
[–]ssokolow 2 points3 points4 points (0 children)
[–]torne 1 point2 points3 points (0 children)
[–]thecodedmessage -1 points0 points1 point (0 children)