# Self-borrowing data would allow erganomic generativity

**URL:** <https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854>\
**Category:** language design\
**Created:** [November 11, 2024, 5:53pm UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854 "2024-11-11T17:53:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![binarycat](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/binarycat/32/12210_2.png) [@binarycat](https://internals.rust-lang.org/u/binarycat)\
**Post date:** [November 11, 2024, 5:53pm UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/1 "2024-11-11T17:53:55Z")

</div>

generativity and branded types are patterns used by crates like `ghost_cell` to allow safe code to do things it otherwise could not.

however, they have a limitation: because `GhostToken` "borrows" `GhostCell`, the two must always be stored in separate types, making it nearly impossible for library authors to hide the complexity of their implementation behind a single struct.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [November 11, 2024, 6:11pm UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/2 "2024-11-11T18:11:58Z")

</div>

There's a universal agreement that self-referential types would be useful. The problem is only in the fact that they make borrow checking much more complex, and work towards making this possible (by rewriting the borrow checker) is taking years.

---

<div class="post-metadata">

**Author:** ![binarycat](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/binarycat/32/12210_2.png) [@binarycat](https://internals.rust-lang.org/u/binarycat)\
**Post date:** [November 11, 2024, 6:12pm UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/3 "2024-11-11T18:12:56Z")

</div>

yeah, i know. i'm just adding yet-another advantage to the pile, since it's one i doubt a lot of people have thought of.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kpreid/32/8484_2.png) [@kpreid](https://internals.rust-lang.org/u/kpreid)\
**Post date:** [November 11, 2024, 10:01pm UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/4 "2024-11-11T22:01:50Z")

</div>

I wasn’t aware that any existing work on the compiler was aimed at supporting self-reference (unless you count futures/coroutines, which are just a different execution strategy for code that’s borrow checked in the normal fashion). Do you have any links handy that would be further reading?

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/quinedot/32/7294_2.png) [@quinedot](https://internals.rust-lang.org/u/quinedot)\
**Post date:** [November 11, 2024, 10:38pm UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/5 "2024-11-11T22:38:15Z")

</div>

[It's Step 4 in this blog post.](https://smallcultfollowing.com/babysteps/blog/2024/06/02/the-borrow-checker-within/)

---

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [November 18, 2024, 10:15am UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/6 "2024-11-18T10:15:27Z")

</div>

Indeed, some forms of self-borrowing types basically subsume existential lifetimes, which in turn allows "returning a fresh lifetime from a function" rather than having to use the closure callback pattern.

I was aware of this, and probably mentioned it in some discussions, but I don't think it's been very widely discussed indeed. Not sure if there is a nice way we can document this somewhere where it won't be forgotten again for the next iteration of self-borrowing types.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [May 12, 2026, 10:15am UTC](https://internals.rust-lang.org/t/self-borrowing-data-would-allow-erganomic-generativity/21854/7 "2026-05-12T10:15:34Z")

</div>

Closed on May 12, 2026, 10:15am UTC

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