Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-lexical lifetimes on exclusive reference #2246

Open
redentis opened this issue Jul 23, 2024 · 1 comment
Open

Non-lexical lifetimes on exclusive reference #2246

redentis opened this issue Jul 23, 2024 · 1 comment

Comments

@redentis
Copy link

redentis commented Jul 23, 2024

The page talking about "Exclusive References" 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 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?

@djmitche
Copy link
Collaborator

We talk about NLL in https://google.github.io/comprehensive-rust/borrowing/borrowck.html?highlight=lexical

This is one of the places that the course tries to be circular -- the slide you link to is the first "pass" on this topic, and we circle back a few times, including in the "borrow check" slide.

Perhaps:

  • Add a speaker note to the "Exclusive References" slide that Rust is "smart" about when a reference is used, perhaps expanding the text "while x_coord is alive". For the moment, this can be "magic" and reference further explanation later in the course.
  • Fill out a little more detail in the "borrow check" slide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants