Limits of Lifetimes
One might expect it to compile. We call , which mutablyborrows foo
temporarily, but then returns only a shared reference. Thereforewe would expect foo.share()
to succeed as shouldn’t be mutably borrowed.
What happened? Well, we got the exact same reasoning as we did for. We desugar the program and we getthe following:
This program is clearly correct according to the reference semantics we actuallycare about, but the lifetime system is too coarse-grained to handle that.