Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closure arguments are inferred monomorphically #42947

Open
eira-fransham opened this issue Jun 28, 2017 · 1 comment
Open

Closure arguments are inferred monomorphically #42947

eira-fransham opened this issue Jun 28, 2017 · 1 comment
Labels
A-inference Area: Type inference C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@eira-fransham
Copy link

eira-fransham commented Jun 28, 2017

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);
}
@Mark-Simulacrum Mark-Simulacrum added the A-inference Area: Type inference label Jun 28, 2017
@eira-fransham eira-fransham changed the title Bounded higher-ranked lifetimes will never be inferred Closure arguments are inferred monomorphically Jun 30, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 28, 2017
@ExpHP
Copy link
Contributor

ExpHP commented Sep 29, 2021

Dupe of #41078. (at least, that's the issue that seems to have received the most attention; took a bit of searching to find though!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants