-
Notifications
You must be signed in to change notification settings - Fork 525
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
Modify mutable deref rule for &mut T
#1758
base: master
Are you sure you want to change the base?
Conversation
src/expressions.md
Outdated
@@ -241,7 +241,7 @@ The following expressions can be mutable place expression contexts: | |||
* [Temporary values]. | |||
* [Fields][field]: this evaluates the subexpression in a mutable place expression context. | |||
* [Dereferences][deref] of a `*mut T` pointer. | |||
* Dereference of a variable, or field of a variable, with type `&mut T`. | |||
* Dereference of a movable place, with type `&mut T`. This includes variables and their fields, as well as temporaries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Dereference of a movable place, with type `&mut T`. This includes variables and their fields, as well as temporaries. | |
* Dereference of a movable place with type `&mut T`. This includes variables and their fields, as well as temporaries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add an internal link on "movable place" also.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024 I checked something and this might be a bit trickerier. According to [expr.move.movable-place], |
@rustbot author |
This indicates that any movable place expression of type
&mut T
can be dereferenced to yield a mutable place.Presently the rule only lists variables and fields of variables. However, if a
&mut T
is contained within a movableBox
, it is also valid to deref the&mut T
and use the resulting place mutably, even if theBox
was immutable. See the following playgrounds:Box
variableBox
variable (correctly) does not yield a mutable place.