Skip to content

hashmaps3 double borrow #2032

Closed Answered by ryanwhitehouse
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

The compiler is smart enough to distinguish that entry1 is no longer being accessed and therefore allows entry2. After the line

let entry2 = scores.entry(team_2_name).or_insert(team2);

You are no longer allowed to access entry1.

For more info see https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html

Note that a reference’s scope starts from where it is introduced and continues through the last time that reference is used. For instance, this code will compile because the last usage of the immutable references, the println!, occurs before the mutable reference is introduced...

The scopes of the immutable references r1 and r2 end after the println! where they are last used, …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mo8it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #1593 on July 07, 2024 21:22.