google / google/comprehensive-rust
Non-lexical lifetimes on exclusive reference
- Dominant language
- Rust
- Stars
- 33.4k
- Forks
- 2.1k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 10
Description
The page talking about "[Exclusive References](https://google.github.io/comprehensive-rust/references/exclusive.html)" has the following in the speaker notes:
> No other references (shared or exclusive) can exist at the same time, and the referenced value cannot be accessed while the exclusive reference exists. Try making an &point.0 or changing point.0 while x_coord is alive.
I experimented with this on the Rust Playground (see https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=09cab9831d130e6532b11e0b1253153f) and was confused when I *could* make another reference to `&point.0` and I *could* modify `point.0`. My confusion was caused by (mis-)understanding that the `x_coord` reference has block scope.
[Non-lexical scoping](https://blog.rust-lang.org/2022/08/05/nll-by-default.html) was introduced in August 2022 / rust 1.63 so this isn't a cutting edge concept or implementation in July 2024.
Maybe reference scoping is complex enough that it need a dedicated page rather than an update on the exclusive references page?
Contributor guide
Assessment
This issue has not been assessed yet.