# Recursive type using generic pointer types

**URL:** <https://internals.rust-lang.org/t/recursive-type-using-generic-pointer-types/15136>\
**Category:** language design\
**Created:** [August 4, 2021, 6:46am UTC](https://internals.rust-lang.org/t/recursive-type-using-generic-pointer-types/15136 "2021-08-04T06:46:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmccombs](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tmccombs/32/1845_2.png) [@tmccombs](https://internals.rust-lang.org/u/tmccombs)\
**Post date:** [August 4, 2021, 6:46am UTC](https://internals.rust-lang.org/t/recursive-type-using-generic-pointer-types/15136/1 "2021-08-04T06:46:35Z")

</div>

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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=dc52630e62650d6d8e6f1aee9d6adf09)

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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c6a0ad6fee8ac1739ceaa07d85d8d801), ICE reported at [ICE with recursive type using GAT. · Issue #87750 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/issues/87750)).

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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0679efc9b3c57f9a9c12e61144f83629).

---

<div class="post-metadata">

**Author:** ![elidupree](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/elidupree/32/4304_2.png) [@elidupree](https://internals.rust-lang.org/u/elidupree)\
**Post date:** [August 4, 2021, 1:46pm UTC](https://internals.rust-lang.org/t/recursive-type-using-generic-pointer-types/15136/2 "2021-08-04T13:46:46Z")

</div>

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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d03052f934b430ff6a46b80e0bdbc04c). 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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e74bb794c0c5345e22031e2eb58273ad)... it's just that it hides the GAT from the _enum definition_'s generic parameter.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [November 2, 2021, 1:47pm UTC](https://internals.rust-lang.org/t/recursive-type-using-generic-pointer-types/15136/3 "2021-11-02T13:47:18Z")

</div>

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