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

Add borrowck 6 #30

Merged
merged 1 commit into from
May 14, 2024
Merged

Add borrowck 6 #30

merged 1 commit into from
May 14, 2024

Conversation

Nilstrieb
Copy link
Sponsor Collaborator

It's a fairly easy one, but interesting nevertheless.

@aDotInTheVoid

It's a fairly easy one, but interesting nevertheless.
@aDotInTheVoid
Copy link
Contributor

If and when we do difficultys, we should move this to be earlier, so we can do reborrows 2 (not yet written), so it's not on their minds when they take it

This is basic Rust, but `r1_twice` *does* compile even though `&mut i32` does *not* implement `Copy`!
That's because for `R1`, the reference is not moved into `r1_once`, it is instead *reborrowed*.
Reborrows are a special operation on references that the borrow checker understands and behave like `&mut *x`.
So there is just a new reference passed to `r1_once`, with the original one preserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good explaination, thanks for writing it.

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:3 thansk

@Nilstrieb Nilstrieb merged commit 0dbb101 into main May 14, 2024
2 checks passed
@Nilstrieb Nilstrieb deleted the borrowck6 branch May 14, 2024 17:08
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

Successfully merging this pull request may close these issues.

None yet

2 participants