# Dumping variable lifetimes for visualization?

**URL:** <https://internals.rust-lang.org/t/dumping-variable-lifetimes-for-visualization/16857>\
**Category:** compiler\
**Created:** [June 21, 2022, 6:31am UTC](https://internals.rust-lang.org/t/dumping-variable-lifetimes-for-visualization/16857 "2022-06-21T06:31:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xplorld](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/xplorld/32/9516_2.png) [@xplorld](https://internals.rust-lang.org/u/xplorld)\
**Post date:** [June 21, 2022, 6:31am UTC](https://internals.rust-lang.org/t/dumping-variable-lifetimes-for-visualization/16857/1 "2022-06-21T06:31:03Z")

</div>

I want to write a lifetime visualization tool as a VSCode plugin. For that I tried to find how rustc can generate lifetime ranges of each variable or lifetime identifier. This must exist somewhere in rustc because it has to do the borrow check on top of it.

I did some digging and found there is a flag `-Z nll-facts` that can generate some related info, but those info are presented without associations to the variable names or code positions. I also searched RLS and rust-analyzer and found nothing related to lifetime ranges.

I wonder if there's such a hope to enable rustc generating a mapping from each variable to its lifetimes in code positions.

---

<div class="post-metadata">

**Author:** ![vakaras](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vakaras/32/2156_2.png) [@vakaras](https://internals.rust-lang.org/u/vakaras)\
**Post date:** [June 21, 2022, 9:31am UTC](https://internals.rust-lang.org/t/dumping-variable-lifetimes-for-visualization/16857/2 "2022-06-21T09:31:01Z")

</div>

`-Z nll-facts` produces input files for Polonius, the new borrow checker. You can run Polonius yourself to obtain the lifetime ranges, but these ranges are likely to be different from the ones produced by the borrow checker used in the stable Rust and not that useful for debugging.

Recently a [stable MIR project](https://rust-lang.zulipchat.com/#narrow/stream/320896-project-stable-mir) started that aims to create stable APIs for tools that consume the Rust compiler information as input. You could try describing your use case there.

---

<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:** [September 19, 2022, 9:31am UTC](https://internals.rust-lang.org/t/dumping-variable-lifetimes-for-visualization/16857/3 "2022-09-19T09:31:51Z")

</div>

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