Add a note about scoping differences between *x and *x.deref() as well as a[b] and *a.index(b)#2073
Open
dianne wants to merge 2 commits intorust-lang:masterfrom
Open
Add a note about scoping differences between *x and *x.deref() as well as a[b] and *a.index(b)#2073dianne wants to merge 2 commits intorust-lang:masterfrom
*x and *x.deref() as well as a[b] and *a.index(b)#2073dianne wants to merge 2 commits intorust-lang:masterfrom
Conversation
Contributor
Author
|
The sections on field access expressions and tuple indexing expressions may also benefit from similar examples or links to that example, in case it needs clarifying that the way they autoderef is scoped more like repeatedly applying |
This comment was marked as resolved.
This comment was marked as resolved.
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
d8c164b to
ddc1d58
Compare
Contributor
Author
|
@rustbot ready I'll open a separate PR to add text for |
8237642 to
cefcfac
Compare
*x and *x.deref()*x and *x.deref() as well as a[b] and *a.index(b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The section on
*operators states that an overloaded*xis equivalent in immutable place expression contexts to*std::ops::Deref::deref(&x)and that it is equivalent in mutable place expression contexts to*std::ops::DerefMut::deref_mut(&mut x). That isn't quite true for their temporary scopes, so this PR adds a note including an example where the difference affects static semantics.There's a similar section for index expressions defining
a[b]in terms of associated function calls, so I've added a comparable example for temporary scoping differences there as well.