hashmaps3 double borrow #2032
-
Hello, I am new with Rust! Trying to solve the exercise like this:
produces the following error:
which makes sense because I am borrowing 2 mutable references to scores entries. But when I permute the code like this
it compiles and pass the test. Why this change make it work? I guess the compiler should not be able to distinguish that the entries are different by just looking at the code in both scenarios. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The compiler is smart enough to distinguish that entry1 is no longer being accessed and therefore allows entry2. After the line
You are no longer allowed to access entry1. For more info see https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
|
Beta Was this translation helpful? Give feedback.
The compiler is smart enough to distinguish that entry1 is no longer being accessed and therefore allows entry2. After the line
You are no longer allowed to access entry1.
For more info see https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html