-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect lifetime inferred for closure #26937
Comments
See also #24680 |
A similar example: fn caller<F>(f: F)
where F: Fn(&i32)
{
f(&42);
}
fn main() {
// Works
caller(|a| println!("{}", a));
// Doesn't work
let f = |a| println!("{}", a);
caller(f);
} I think the problem is that in the non-working case,
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 If you force the closure to understand that the argument must be a reference, you get the same error but more sensible: fn printer(a: &i32) { println!("{}", a) }
let f = |a| printer(a);
caller(f)
This appears to be discussed in #24680, as @seanmonstar mentioned. |
Closing in favor of #41078. |
Example:
Fails with:
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 text was updated successfully, but these errors were encountered: