Hacker News new | ask | show | jobs
by gnuvince 2694 days ago
I admit that I'm very unexcited about non-lexical lifetimes—the cost-to-benefit ratio seems worse than the current model. The current lifetime system is simple to understand: a value is live until its owning variable goes out of scope. It can be a bit restrictive sometimes (though it seems that after a while you learn how to work around those issues easily enough), but it's easy to keep in your head and reason about code. With non-lexical lifetimes, I think that we'll have a harder time understanding lifetimes, it'll be more difficult to teach them and to debug them.
1 comments

My understanding is that the semantics are exactly the same, but it’s just possible for the checker to match your intent more tightly.

For example, in lexical lifetimes, this fails:

    let x = &mut foo;
    
    if x.bar() {
        baz()
    } else {
        foo.consume() // takes foo by value
    }
It will complain that you’ve used `foo` while it is borrowed by `x`, even though a human can easily tell that `x` is already irrelevant by that point. NLL would accept this (I believe).