Skip to content

calling opaque types and Copy closures footgun #230

Description

@lcnr
fn item_bound_is_too_weak(b: bool) -> impl FnOnce() -> u32 {
    if b {
        let mut var = item_bound_is_too_weak(false);
        println!("{}", var());
        println!("{}", var());
    }

    let mut state = 0u32;
    move || {
        state += 1;
        state
    }
}

fn main() {
    item_bound_is_too_weak(true);
}

this results in 1 1 because we unnecessarily assume the fn call to be FnOnce which then copies the closure. Should mention in the stabilization report and also... maybe lint when copying closures xd

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions