3 ms·
If I understand the article, what's already the case is that any reuse of "a" while "b" exists is illegal. Which is simple and uncomplicated and you can work ar
by JulianMorrison 11y ago
If I understand the article, what's already the case is that any reuse of "a" while "b" exists is illegal. Which is simple and uncomplicated and you can work around it like this
let a = 1
begin block scope {
let b = pointer to a
do_stuff(b)
} // end block scope and b is dead
do_other_stuff (a)
What the change would do is make that block scope exist, but it exists implicitly and invisibly. And it invisibly stretches over the call to do_other_stuff(a) by the insertion of the do_more_stuff(b) below it. And suddenly it breaks.
Contrast:
let a = 1
begin block scope {
let b = pointer to a
do_stuff(b)
} // end block scope and b is dead
do_other_stuff (a)
// ... etc etc
do_more_stuff(b) // is obviously broken, b is not in scope
or
let a = 1
begin block scope {
let b = pointer to a
do_stuff(b)
do_other_stuff (a) // is obviously broken, b is not dead
// ... etc etc
do_more_stuff(b)
} // end block scope way down here
- kibwen 11y agoGiven that the Rust team is committed to introducing non-lexical lifetimes backwards-compatibly, by definition that means that no code that compiles today will be invalidated by the feature's addition. Which means that the only instances of concern being raised here are programs which are already invalid in today's Rust, which is to say that any workarounds for these theoretical problems are already mandatory. There's nothing "breaking" here that isn't already broken. It's a strict reduction in the number of programs that will be rejected by the borrow checker.