You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/operator-expr.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -189,6 +189,30 @@ let y = &mut 9;
189
189
assert_eq!(*y, 11);
190
190
```
191
191
192
+
> [!NOTE]
193
+
> The [temporary scopes][temporary scope] of `x` in `*x` and `*std::ops::Deref::deref(&x)` are not always the same in all immutable place expression contexts.
194
+
> Likewise, the temporary scopes of `x` in `*x` and `*std::ops::DerefMut::deref_mut(&mut x)` are not always the same in all mutable place expression contexts.
195
+
>
196
+
> If `*x` has an [extended][temporary lifetime extension] temporary scope, then `x` does as well ([destructors.scope.lifetime-extension.sub-expressions]).
197
+
> However, the same does not apply to `*std::ops::Deref::deref(&x)` or `*std::ops::DerefMut::deref_mut(&mut x)`.
198
+
>
199
+
> For example:
200
+
>
201
+
> ```rust
202
+
> // The temporary holding the result of `String::new()` is extended
203
+
> // to live to the end of the block, so `x` may be used in subsequent
204
+
> // statements.
205
+
> letx=&*String::new();
206
+
> # x;
207
+
> ```
208
+
>
209
+
> ```rust,compile_fail,E0716
210
+
> // The temporary holding the result of `String::new()` is dropped at
211
+
> // the end of the statement, so it's an error to use `y` after.
0 commit comments