Skip to content

Integer fallback error with closures #20880

@mandel59

Description

@mandel59
fn foo<T>(mut f: T) where T: FnMut() {
    f();
}

#[cfg(error)]
fn bar() {
    let n = 42;
    foo(|| { println!("{}", n); });
}

#[cfg(not(error))]
fn bar() {
    let n: i32 = 42;
    foo(|| { println!("{}", n); });
}

fn main() {
    bar();
}

This yields the following error:

% rustc infer_int.rs --cfg error
infer_int.rs:8:5: 8:8 error: unable to infer enough type information about `closure[infer_int.rs:8:9: 8:34]`; type annotations required
infer_int.rs:8     foo(|| { println!("{}", n); });
                   ^~~
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions