Recursive type using generic pointer types

Following the announcement of GATs being no longer "incomplete". I thought I might see if I could use it to make an equivalent of the single linked list that is generic in the pointer type (so it can be used with both Rc and Arc). Unfortunately, it is more difficult than I had hoped, and might be impossible. My initial attempt was Rust Playground

Unfortunately, I got an error for overflow evaluating the requirement for the Sized trait. With some more constraints, I was able to get the Node type to compile, but when I try to instantiate I get an ICE (Rust Playground, ICE reported at ICE with recursive type using GAT. · Issue #87750 · rust-lang/rust · GitHub).

So my questions are:

  1. Is there some way to get this to work?
  2. If not, is it worth exploring a way to support doing things like this?

FWIW, I also tried doing something similar without GAT, and was able to get something that seems to work, although it is less elagant: Rust Playground.

Interesting! I've done something similar to this, but much more sophisticated, so I was surprised that this didn't work. It looks like the difference is the fact that you've used an enum instead of a struct: here's a version that works. I wonder why making it an enum is breaking it?

UPDATE: In fact, here's a version that does use an enum and has the same structure in memory as your version... it's just that it hides the GAT from the enum definition's generic parameter.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.