Skip to content

Commit d69cf92

Browse files
committed
Clarify text about lvalues
1 parent 18fe78e commit d69cf92

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

text/0803-type-ascription.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ context of cross-platform programming).
153153
### Type ascription and temporaries
154154

155155
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:
160160

161161
```
162162
let mut foo: S = ...;
@@ -172,11 +172,13 @@ lvalue position), then we don't have the soundness problem, but we do get the
172172
unexpected result that `&(x: T)` is not in fact a reference to `x`, but a
173173
reference to a temporary copy of `x`.
174174

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):
180182

181183
```
182184
&[mut] <expr>

0 commit comments

Comments
 (0)