The rule defined in 2094-nll - The Rust RFC Book says:
For deep accesses to the path
lvalue
, we consider borrows relevant if they meet one of the following criteria:
- there is a loan for the path
lvalue
;
Consider this example
fn main(){
let mut i = 0;
let rf = &i;
let mut b = 0;
b = i; // #1 deep read
println!("{rf}");
}
#1
is a deep read to i
and is ok, however, there is a loan for path i
. Is the bullet too brief to be not good enough to cover all the cases?
It seems to make sense to talk about what kind of loans are for different kinds of deep access.
- For deep read to the path
lvalue
, there is a mutable loan for the pathlvalue
- For deep write to the path
lvalue
, there is a loan for the pathlvalue
I suppose we should also have a case-by-case discussion for the rule:
there is a loan for some prefix of the path
lvalue
;
Is something I misunderstand?