@@ -153,10 +153,10 @@ context of cross-platform programming).
153
153
### Type ascription and temporaries
154
154
155
155
There is an implementation choice between treating ` x: T ` as an lvalue or
156
- rvalue. Note that when a rvalue is used in lvalue context (e.g., the subject of
157
- a reference operation), then the compiler introduces a temporary variable.
158
- Neither option is satisfactory, if we treat an ascription expression as an
159
- lvalue (i.e., no new temporary), then there is potential for unsoundness:
156
+ rvalue. Note that when an rvalue is used in 'reference context' (e.g., the
157
+ subject of a reference operation), then the compiler introduces a temporary
158
+ variable. Neither option is satisfactory, if we treat an ascription expression
159
+ as an lvalue (i.e., no new temporary), then there is potential for unsoundness:
160
160
161
161
```
162
162
let mut foo: S = ...;
@@ -172,11 +172,13 @@ lvalue position), then we don't have the soundness problem, but we do get the
172
172
unexpected result that ` &(x: T) ` is not in fact a reference to ` x ` , but a
173
173
reference to a temporary copy of ` x ` .
174
174
175
- The proposed solution is that type ascription expressions are lvalues. If the
176
- type ascription expression is in reference context, then we require the ascribed
177
- type to exactly match the type of the expression, i.e., neither subtyping nor
178
- coercion is allowed. These reference contexts are as follows (where <expr > is a
179
- type ascription expression):
175
+ The proposed solution is that type ascription expressions inherit their
176
+ 'lvalue-ness' from their underlying expressions. I.e., ` e: T ` is an lvalue if
177
+ ` e ` is an lvalue, and an rvalue otherwise. If the type ascription expression is
178
+ in reference context, then we require the ascribed type to exactly match the
179
+ type of the expression, i.e., neither subtyping nor coercion is allowed. These
180
+ reference contexts are as follows (where ` <expr> ` is a type ascription
181
+ expression):
180
182
181
183
```
182
184
&[mut] <expr>
0 commit comments