-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Hi! I'm currently studying the section on "Aliasing and Mutation" in the Rust Book Experiment, and I noticed a phrasing that might be slightly misleading for students.
"Pointers are a powerful and dangerous feature because they enable aliasing... One variable can 'pull the rug out' from another variable in many ways, for example: By deallocating the aliased data, leaving the other variable to point to deallocated memory."
The Point of Confusion: In Rust, a reference (&T or &mut T) does not own the data it points to and therefore cannot deallocate it. The current wording might lead a student to believe that a reference itself has the power to trigger a deallocation.
Suggested Improvement: To reinforce the core concept of Ownership, it might be clearer to specify that it is the owner (or a smart pointer like Box) that performs the deallocation, which then affects any existing aliases. Perhaps something like:
"By having the owner deallocate the aliased data (for instance, through a mutation like vec.push() or by dropping the owner), leaving any existing references to point to invalidated memory."
Why it matters: This distinction helps the student visualize the reference as a passive victim of the owner's actions. It reinforces the mental model that while a reference is an observer, it is entirely dependent on the owner's stability.