Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Rust Book Quiz Ch 15.5, Interior Mutability
Hello!
I am currently working through the Rust Book (Brown University version). The quizzes really help a lot to keep me on my toes, but now I stumbled upon a question / solution I don't fully understand.
The final quiz of Chapter 15.5 asks which of the code snippets would violate memory safety.
I get why this would be the case in the correct answer (the vector could have been relocated due to the push, so the reference to its first element might be invalid).
But I don't understand why option 4 would be fine. My reasoning: with the first push, the vector might have been relocated, so the push with the second reference might be referencing an invalid location.
So I am clearly missing something here!
Could anybody give me a hint? I would really appreciate it!
Best regards!
5 posts - 3 participants
🏷️ Rust_feed