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

Inference failure with mutable reference to closure #34892

Closed
eefriedman opened this issue Jul 17, 2016 · 3 comments
Closed

Inference failure with mutable reference to closure #34892

eefriedman opened this issue Jul 17, 2016 · 3 comments

Comments

@eefriedman
Copy link
Contributor

fn foo<'a, X:'static>(mut cb: &mut (FnMut(&u64) -> X + 'a)) -> X {
    let mut cb = move |expr1| {
        cb(expr1)
    };
    let cb = &mut cb;
    foo(cb)
}

// Alternate version which works
fn id<X, T: FnMut(&u64) -> X>(t: T) -> T { t }
fn foo2<'a, X:'static>(mut cb: &mut (FnMut(&u64) -> X + 'a)) -> X {
    let mut cb = id(move |expr1| {
        cb(expr1)
    });
    let cb = &mut cb;
    foo2(cb)
}

Gives:

error: type mismatch: the type `[closure@<anon>:2:18: 4:6 cb:_]` implements the trait `std::ops::FnMut<(&u64,)>`, but the trait `for<'r> std::ops::FnMut<(&'r u64,)>` is required (expected concrete lifetime, found bound lifetime parameter ) [--explain E0281]
 --> <anon>:6:9
  |>
6 |>     foo(cb)
  |>         ^^
note: required for the cast to the object type `for<'r> std::ops::FnMut(&'r u64) -> X`

error: type mismatch resolving `for<'r> <[closure@<anon>:2:18: 4:6 cb:_] as std::ops::FnOnce<(&'r u64,)>>::Output == X`:
 expected bound lifetime parameter ,
    found concrete lifetime [--explain E0271]
 --> <anon>:6:9
  |>
6 |>     foo(cb)
  |>         ^^
note: required for the cast to the object type `for<'r> std::ops::FnMut(&'r u64) -> X`

error: aborting due to 2 previous errors
@arielb1
Copy link
Contributor

arielb1 commented Jul 18, 2016

Yeah. Higher-ranked inference is an undecidable mess.

@DemiMarie
Copy link
Contributor

Can the compiler be made to loop this way?

@Mark-Simulacrum
Copy link
Member

Closing in favor of #41078.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants