29 ms·
This example is just infinite recursion. You will get a similar result in, say, Python. Maybe the author wanted to say that Rust (currently) doesn't perform an
by fulafel 9y ago
This example is just infinite recursion. You will get a similar result in, say, Python.
Maybe the author wanted to say that Rust (currently) doesn't perform an optimization called tail call elimination that would make this program consume zero stack, which would make it hang instead of erroring out.
Some languages (like Scheme) are specified to optimize tail calls, so you can rely on this behaviour there.
- steveklabnik 9y agoTo be clear about this, LLVM will sometimes do TCO. But Rust doesn't guarantee it. We have reserved a keyword to make this happen sometimes in the future, possibly.