Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRust has trouble seeing higher ranked lifetimes through generics #36582
Comments
This comment has been minimized.
This comment has been minimized.
Stebalien
changed the title
Rust has trouble seeing HRL through generics
Rust has trouble seeing higher ranked lifetimes through generics
Sep 19, 2016
TimNN
added
the
A-typesystem
label
Sep 19, 2016
This comment has been minimized.
This comment has been minimized.
iopq
commented
Sep 20, 2016
|
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. |
This comment has been minimized.
This comment has been minimized.
|
That's an inherent limitation - generic type parameters can only be instantiated monomorphically: |
This comment has been minimized.
This comment has been minimized.
|
Then how does |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@arielb1 Sorry, I should have explained further. Here, I'm asking that rust use this knowledge to infer that |
This comment has been minimized.
This comment has been minimized.
|
As a trait object? The problem is that
|
This comment has been minimized.
This comment has been minimized.
|
@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. |
Stebalien commentedSep 19, 2016
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 thatidimplementsfor<'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.