-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Generic fn cannot be converted to for<'a> Fn
#22791
Comments
Changing the lifetime names to ease understanding use std::marker::PhantomFn;
struct Foo(Bar);
struct Bar;
trait BorrowFn<'a>: PhantomFn<&'a Self, ()> {}
impl<'b, T: 'b, F: Fn(&'b Foo) -> T> BorrowFn<'b> for F {}
fn something<F>(_: F) where for<'c> F: BorrowFn<'c> {}
fn foo_as_bar<'d>(x: &'d Foo) -> &'d Bar { &x.0 }
fn main() {
something(foo_as_bar);
} The errors: <anon>:14:5: 14:14 error: the requirement `for<'c> _ : 'c` is not satisfied [E0280]
<anon>:14 something(foo_as_bar);
^~~~~~~~~
<anon>:14:5: 14:14 error: type mismatch resolving `for<'c> <fn(&'d Foo) -> &'d Bar {foo_as_bar} as core::ops::Fn<(&'c Foo,)>>::Output == _`:
expected bound lifetime parameter 'c,
found concrete lifetime [E0271]
<anon>:14 something(foo_as_bar);
^~~~~~~~~
<anon>:14:5: 14:14 note: required by `something`
<anon>:14 something(foo_as_bar);
^~~~~~~~~ Note that |
The |
for<'a> Fn
Possibly related to #22340 |
This is still an issue after removing the outdated |
@apasel422 do you remember how to do so? getting a compileable example in this ticket would be helpful |
I think the current version of this code is: struct Foo(Bar);
struct Bar;
trait BorrowFn<'a> {}
impl<'b, T: 'b, F: Fn(&'b Foo) -> T> BorrowFn<'b> for F {}
fn something<F>(_: F) where for<'c> F: BorrowFn<'c> {}
fn foo_as_bar<'d>(x: &'d Foo) -> &'d Bar { &x.0 }
fn main() {
something(foo_as_bar);
} |
Closing in favor of #41078. |
This code causes a compile error, but I think that it should compile without problems.
playpen
The compile errors:
cc @reem This is from the code I showed to you on IRC.
The text was updated successfully, but these errors were encountered: