Note scoping differences between *x and *x.deref() , and a[b] and *a.index(b)#2073
Note scoping differences between *x and *x.deref() , and a[b] and *a.index(b)#2073dianne wants to merge 2 commits intorust-lang:masterfrom
*x and *x.deref() , and a[b] and *a.index(b)#2073Conversation
|
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.
|
Reminder, once the PR becomes ready for a review, use |
d8c164b to
ddc1d58
Compare
|
@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)
src/expressions/array-expr.md
Outdated
| @@ -90,6 +90,30 @@ r[expr.array.index.trait] | |||
| For other types an index expression `a[b]` is equivalent to `*std::ops::Index::index(&a, b)`, or `*std::ops::IndexMut::index_mut(&mut a, b)` in a mutable place expression context. | |||
There was a problem hiding this comment.
When looking at this, we felt that this probably shouldn't be part of a note, but instead should be incorporated into the rule itself. The "is equivalent to" is not entirely true due to this exception. How about just adding this text here:
| For other types an index expression `a[b]` is equivalent to `*std::ops::Index::index(&a, b)`, or `*std::ops::IndexMut::index_mut(&mut a, b)` in a mutable place expression context. | |
| For other types an index expression `a[b]` is equivalent to `*std::ops::Index::index(&a, b)`, or `*std::ops::IndexMut::index_mut(&mut a, b)` in a mutable place expression context, except that when the index expression undergoes [temporary lifetime extension], the indexed expression `a` also has its temporary lifetime extended. |
and then include the rust example as you have.
There was a problem hiding this comment.
Seems good to me! I couldn't figure out a way to keep the link to destructors.scope.lifetime-extension.sub-expressions without it getting overly cluttered, but maybe it's fine to leave it out?
cefcfac to
004be03
Compare
This comment has been minimized.
This comment has been minimized.
*x and *x.deref() as well as a[b] and *a.index(b)*x and *x.deref() , and a[b] and *a.index(b)
004be03 to
8e4d81a
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
The equivalences between the overloaded operator expressions and their associated function call forms don't hold in the presence of temporary lifetime extension; this adjusts the rules accordingly and adds examples.