I find the borrow checker has a strange behavior when borrows are encapsulated. For example the following code:
is not accepted by the borrow checker, yet it is (should be?) equivalent to
let res = foo.fun1_with_mut_borrow(); foo.fun0_with_imm_borrow(res);
which does compile without problem.
Is there any reason behind this design?
Here is an example of the issue in the rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f682ebef4702a0ca5d3215e9dd3b632b