From f1428da59145784a69a0ab06f730d8219fc4ad5e Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sat, 3 Oct 2026 01:36:14 -0400 Subject: [PATCH 1/2] Reorder expr.mut above expr.move --- src/expressions.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/expressions.md b/src/expressions.md index 9943384dcf..6cf5b99123 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -190,6 +190,24 @@ An *assignee expression* is an expression that appears in the left operand of an r[expr.place-value.parenthesis] Arbitrary parenthesisation is permitted inside assignee expressions. +r[expr.mut] +### Mutability + +r[expr.mut.intro] +For a place expression to be [assigned][assign] to, mutably [borrowed][borrow], [implicitly mutably borrowed], or bound to a pattern containing `ref mut`, it must be _mutable_. We call these *mutable place expressions*. In contrast, other place expressions are called *immutable place expressions*. + +r[expr.mut.valid-places] +The following expressions can be mutable place expression contexts: + +* Mutable [variables] which are not currently borrowed. +* [Mutable `static` items]. +* [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`. Note: This is an exception to the requirement of the next rule. +* Dereferences of a type that implements `DerefMut`: this then requires that the value being dereferenced is evaluated in a mutable place expression context. +* [Array indexing] of a type that implements `IndexMut`: this then evaluates the value being indexed, but not the index, in mutable place expression context. + r[expr.move] ### Moved and copied types @@ -216,24 +234,6 @@ After moving out of a place expression that evaluates to a local variable, the l r[expr.move.place-invalid] In all other cases, trying to use a place expression in a value expression context is an error. -r[expr.mut] -### Mutability - -r[expr.mut.intro] -For a place expression to be [assigned][assign] to, mutably [borrowed][borrow], [implicitly mutably borrowed], or bound to a pattern containing `ref mut`, it must be _mutable_. We call these *mutable place expressions*. In contrast, other place expressions are called *immutable place expressions*. - -r[expr.mut.valid-places] -The following expressions can be mutable place expression contexts: - -* Mutable [variables] which are not currently borrowed. -* [Mutable `static` items]. -* [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`. Note: This is an exception to the requirement of the next rule. -* Dereferences of a type that implements `DerefMut`: this then requires that the value being dereferenced is evaluated in a mutable place expression context. -* [Array indexing] of a type that implements `IndexMut`: this then evaluates the value being indexed, but not the index, in mutable place expression context. - r[expr.temporary] ### Temporaries From 99673e13d10d7f9820df619ad35deadf8f039179 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sat, 3 Oct 2026 01:45:35 -0400 Subject: [PATCH 2/2] Document universal `&mut` reborrows --- src/expressions.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/expressions.md b/src/expressions.md index 6cf5b99123..03b1f4dbec 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -217,6 +217,9 @@ When a place expression is evaluated in a value expression context, or is bound r[expr.move.copy] If the type of that value implements [`Copy`], then the value will be copied. +r[expr.move.mut-ref] +If the type of that value is `&mut T`, and the place expression is mutable, then the value will be reborrowed. This is equivalent to applying `&mut *` (a [dereference][deref] and then a [mutable borrow][borrow]) to the place. + r[expr.move.requires-sized] In the remaining situations, if that type is [`Sized`], then it may be possible to move the value.