Skip to content

Closure arguments are inferred monomorphically #42947

Open
@eira-fransham

Description

@eira-fransham

Without an explicit annotation, closure arguments are inferred to have a concrete lifetime. You must manually annotate the argument in order to satisfy a HRTB.

#[derive(PartialEq)]
struct Foo;

fn use_a_foo(_: &Fn(&Foo)) {}

fn main() -> () {
    // This doesn't compile
    // let function = |foo_arg| {
    //   assert!(&foo == foo_arg);
    // };
    // explicit_for(&foo, &function);

    // This does
    let function = |foo_arg: &_| {};
    use_a_foo(&function);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions