Skip to content

Closure parameter inference and lifetime elision mayhem #24421

Closed
@frankmcsherry

Description

@frankmcsherry

If you throw the following code into playpen, in the fourth case (by my reading of the error message) Rust determines an incompatible number of lifetime parameters for<'r> core::ops::Fn<(&'r u64, &'r u64)> vs. for<'r,'r> core::ops::Fn<(&'r u64, &'r u64)>).

fn test<F: Fn(&u64, &u64)>(f: F) {}

fn main() {
    test(|x,      y     | {});   // works  
    test(|x:&u64, y:&u64| {});   // works
    test(|x:&u64, y     | {});   // works
    test(|x,      y:&u64| {});   // no works
}

I won't try to explain how mysterious this was, manifesting as a "sorry, you don't implement that trait" error (because the closure was not matching the type) without explaining what was awry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions