cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
503 stars 82 forks source link

[chapter 5-3] Losing R permission makes no sense #177

Closed Archsx closed 1 week ago

Archsx commented 3 months ago

URL to the section(s) of the book with this problem: https://rust-book.cs.brown.edu/ch05-03-method-syntax.html Description of the problem:

when using a immutable reference to refer a variable, it shows the variable(rect) losses the R permission. Screenshot from 2024-04-01 14-56-34

Suggested fix:

twhentschel commented 2 months ago

I'm still learning this, but perhaps it's because the variable rect is no longer used after that point in the program, so it loses all permissions.

I redid this example in aquascope (the program that makes these type of borrow-checking figures in the book) but used rect one more time after it was aliased and this is what I got: image

willcrichton commented 1 week ago

@twhentschel's explanation is exactly correct. It's an open issue in Aquascope to make these cases clearer. Hopefully we will improve this soon. See: cognitive-engineering-lab/aquascope#85