Why does the compiler report an error after replacing mark 2 with a mark 1 sentence? Essentially, there is no significant difference between the two, so is this a shortcoming of the compiler?
This means the whole self would be borrowed for &'a [usize], unlike mark 2 where only field self.a would be borrowed.
I think this is correct behavior(it should be rejected). If this was allowed you can break outer code by changing get_a to return self.b instead of self.a.
You can basically consider the function signature to be a contract between caller and callee. Changes to the function body don't change the contract, so can't break downstream code.[1] Or from the other point of view, the caller must assume the function body does everything allowed by the contract.
The contract in this case is indeed "all of self is borrowed".[2]
The ability to borrow individual fields in function bodies is also called borrow splitting.
there are some exceptions around opaque return types and auto-traits ↩︎
there's an interest in more refined borrow signatures and/or functions that leak their borrowing details, but they're probably a ways off. See also "view types" ↩︎