cognitive-engineering-lab / aquascope

Interactive visualizations of Rust at compile-time and run-time
https://cognitive-engineering-lab.github.io/aquascope/
MIT License
2k stars 46 forks source link

incorrect permissions analysis #128

Closed k-yang closed 8 months ago

k-yang commented 8 months ago

The following is a valid Rust program (compiles without errors). Why doesn't the *n path have the write permission?

Screenshot 2024-03-06 at 2 18 21 PM

gavinleroy commented 8 months ago

Fortunately, Aquascope is telling you the truth, that this program is not valid. Here's a playground link.

On line 3, n is a shared reference, meaning that memory behind the reference cannot be mutated. Aquascope indicates this by saying *n gains read (R) permission but neither write (W) nor own (O) permission. This leads to the permissions violation on line 4.

However, the interpreted program shows that it runs without error. That is, if Rust did allow the program to run it doesn't crash. (Note that we bypass compiler errors to interpret the program, but rustc would not provide a binary for this program.)

For more on references and borrowing, please refer to Chapter 4 in The Rust Book Experiment.