-
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
Rust has trouble seeing higher ranked lifetimes through generics #36582
Comments
I'm currently not able to use the library version of the function because of this limitation and I have to "specialize" manually by adding my own definition. This defeats the point of having libraries for functional programming in Rust, since the code doesn't compile due to this limitation. |
That's an inherent limitation - generic type parameters can only be instantiated monomorphically: |
Then how does |
|
@arielb1 Sorry, I should have explained further. Here, I'm asking that rust use this knowledge to infer that |
As a trait object? The problem is that
|
@arielb1 Types which are higher-rank over lifetimes only don't suffer from impredicativity issues, no? You can't self-reference because they aren't of the correct kind for the higher-rank parameter. Not saying they wouldn't be complicated to implement, just that I don't think they necessarily introduce decidability problems. |
Triage: this still fails to compile. |
Triage: current output
|
Rust has trouble seeing that a generic function is "generic" over higher ranked lifetimes. This behavior is best described by example. Given:
Rust complains:
However, the
has_hrl(id_wrapped)
andhas_hrl(|x| id(x))
calls demonstrate that, at some level, the rust type checker infers thatid
implementsfor<'r> Fn(&'r ()) -> &'r ()
. That's why I filed this as a bug instead of an RFC issue. However, I can move this if you feel that it's too much of a feature request.My motivation is functional programming. Not being able to infer that a generic function is defined for some HRL makes it impossible to use such functions with, e.g.,
Iterator::filter
.The text was updated successfully, but these errors were encountered: