Skip to content

Type inference failure when passing a closure in place of a function parameter #15148

Closed
@ghost

Description

pub struct Foo<A,B> {
    f: fn(A, B) -> bool
}

impl<A,B> Foo<A,B> {
    pub fn new(f: fn(A, B) -> bool) -> Foo<A,B> {
        Foo { f: f }
    }
}

fn main() {
    let foo = Foo::<bool,bool>::new(|a,b| -> bool { a && b });
}

main.rs:15:57: 15:58 error: the type of this value must be known in this context
main.rs:15 let foo = Foo::<bool,bool>::new(|a,b| -> bool { a && b });

It does work when changing the code to expect a closure rather than a function, or when passing the expected function, but the error message here is either wrong/misleading, or there's a real bug.

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