Skip to content

Commit 9004bcd

Browse files
committed
Modify RFC rust-lang#803 (type ascription) to make type ascription expressions lvalues.
1 parent f77d562 commit 9004bcd

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

text/0803-type-ascription.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ 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 rvalues, but
176-
taking a reference of such an expression is forbidden. I.e., type asciption is
177-
forbidden in the following contexts (where `<expr>` is a type ascription
178-
expression):
175+
The proposed solution is that type ascription expressions are lvalues, where
176+
the type ascription expression is in reference context, then we require the
177+
ascribed type to exactly match the type of the expression, i.e., neither
178+
subtyping nor coercion is allowed. These contexts are:
179179

180180
```
181181
&[mut] <expr>
@@ -184,12 +184,6 @@ match <expr> { .. ref [mut] x .. => { .. } .. }
184184
<expr>.foo() // due to autoref
185185
```
186186

187-
Like other rvalues, type ascription would not be allowed as the lhs of assignment.
188-
189-
Note that, if type asciption is required in such a context, an lvalue can be
190-
forced by using `{}`, e.g., write `&mut { foo: T }`, rather than `&mut (foo: T)`.
191-
192-
193187
# Drawbacks
194188

195189
More syntax, another feature in the language.

0 commit comments

Comments
 (0)