4 ms·
That doesn't really make much sense for Rust, unfortunately. That is, for stack objects, LLVM/etc already do this and lifetimes don't add any useful new inform
by Rusky 5y ago
That doesn't really make much sense for Rust, unfortunately.
That is, for stack objects, LLVM/etc already do this and lifetimes don't add any useful new information. A function will generally adjust the stack pointer once to allocate and free space for all its locals together.
Beyond that, lifetimes are answering the wrong question. For one thing, the language goes to great lengths to squash and stretch lifetimes to accept more programs- so function signatures are typically as general as possible (IOW they capture as little lifetime information as possible). This even includes entirely "forgetting" information about how/where things are allocated.
Actually using lifetimes or "regions" to control or track allocations probably makes more sense in a higher-level, perhaps more allocation-happy, language. You might be interested in looking at Vale, for example: https://vale.dev/ https://vale.dev/