I'm making a small type-level program that computes the last element of a type-level list. Compiler is rustc 1.51.0-nightly (80184183b 2021-01-03). This program works correctly:
error[E0275]: overflow evaluating the requirement `Cons<_, _>: GetLast`
|
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`test`)
= note: required because of the requirements on the impl of `GetLast` for `Cons<_, Cons<_, _>>`
= note: 127 redundant requirements hidden
= note: required because of the requirements on the impl of `GetLast` for `Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, Cons<_, _>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
I tried increasing the recursion limit, but rustc just eventually segfaults.
I recognize this issue is using two unstable features (GATs and specialization), so it's not surprising that this didn't work. But I wanted to raise the issue in case it helps solve an issue in specialization phase.
The issue
I'm making a small type-level program that computes the last element of a type-level list. Compiler is
rustc 1.51.0-nightly (80184183b 2021-01-03). This program works correctly:My goal is to turn
GetLastinto a higher-order type function, via the family pattern and GATs.However, this code doesn't compile unless
GetLastis implemented for all typesT. So I'm trying to use specialization to achieve this:Then the compiler returns the error:
I tried increasing the recursion limit, but rustc just eventually segfaults.
An undesirable fix
I determined that if I change the logic of the
GetLastimpls, then I can get the code to compile. Specifically, rather than enforcingCons<Head, Nil>andCons<Head, Cons<Head2, Tail2>>to be distinct types, I can make the latter also a default type.However, I'd like to avoid this solution because my goal is to produce an automated translation from a high-level language, and this default trickery isn't straightforward.
I recognize this issue is using two unstable features (GATs and specialization), so it's not surprising that this didn't work. But I wanted to raise the issue in case it helps solve an issue in specialization phase.