You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<anon>:12:16: 12:18 error: type mismatch resolving `for<'r> <[closure <anon>:11:17: 11:43] as core::ops::FnOnce<(&'r str,)>>::Output == ()`:
expected bound lifetime parameter, found concrete lifetime [E0271]
<anon>:12 Z::new(&c);
^~
<anon>:12:16: 12:18 help: see the detailed explanation for E0271
<anon>:12:16: 12:18 note: required for the cast to the object type `for<'r> core::ops::FnMut(&'r str)`
<anon>:12 Z::new(&c);
^~
<anon>:12:16: 12:18 error: type mismatch: the type `[closure <anon>:11:17: 11:43]` implements the trait `core::ops::FnMut<(_,)>`, but the trait `for<'r> core::ops::FnMut<(&'r str,)>` is required (expected concrete lifetime, found bound lifetime parameter ) [E0281]
<anon>:12 Z::new(&c);
^~
<anon>:12:16: 12:18 note: required for the cast to the object type `for<'r> core::ops::FnMut(&'r str)`
<anon>:12 Z::new(&c);
^~
The problem can be worked around by writing |s: &str| instead of just |s|, but according to @eddyb this behaviour should be improved to infer the correct lifetime.
The error reporting stops at the "expected concrete lifetime, found bound lifetime parameter" aspect, but really the problem is that the closure argument isn't a reference. I'd expect to see Fn<(&_,)>.
If you force the closure to understand that the argument must be a reference, you get the same error but more sensible:
fnprinter(a:&i32){println!("{}", a)}let f = |a| printer(a);caller(f)
Activity
seanmonstar commentedon Jul 28, 2015
See also #24680
shepmaster commentedon May 30, 2016
A similar example:
I think the problem is that in the non-working case,
aisn't inferred to be a reference at all. The error message states (reworded a bit):The error reporting stops at the "expected concrete lifetime, found bound lifetime parameter" aspect, but really the problem is that the closure argument isn't a reference. I'd expect to see
Fn<(&_,)>.If you force the closure to understand that the argument must be a reference, you get the same error but more sensible:
This appears to be discussed in #24680, as @seanmonstar mentioned.
Mark-Simulacrum commentedon Apr 29, 2017
Closing in favor of #41078.