Spot the bug in the Fn bound

from Closures
Rust 1.98 intermediate 4 min 1 issue to find

Find why this helper rejects a callback that increments captured state.

Rust
fn call_twice<F>(callback: F) -> (u32, u32)
where
    F: Fn() -> u32,
{
    (callback(), callback())
}

fn main() {
    let mut sequence = 0;
    let next = || {
        sequence += 1;
        sequence
    };
    println!("{:?}", call_twice(next));
}
Open in playground
Report an error