3 ms·
> Who said anything about extending "variables"? I did, because that's the only thing that can be kept alive longer than needed (till the end of the scope wher
by littlestymaar 2y ago
> Who said anything about extending "variables"?
I did, because that's the only thing that can be kept alive longer than needed (till the end of the scope where the variable is defined).
> If you heap allocate something and store a reference to it, Rust will absolutely keep that object alive till all such references are gone.
No it doesn't.
And it shows you have no understanding of how Rust works. A GC will do that, but the borrow checker won't, it cannot, all it can do is to yell at you so that you make your variable live as long as it needs.
See this playground to see what happen when you allocate something on the heap and try return a reference to it: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=130bcebf379dbb10dd4b51e649ed83bf https://play.rust-lang.org/?version=stable&mode=debug&editio...
If you could please stop spreading nonsense about a language you don't even know the basics of, that would be great for everyone.