Dumping variable lifetimes for visualization?

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.

1 Like

-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 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.

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