Skip to content

Commit

Permalink
Modify RFC rust-lang#803 (type ascription) to make type ascription ex…
Browse files Browse the repository at this point in the history
…pressions lvalues.
  • Loading branch information
nrc committed Mar 18, 2015
1 parent f77d562 commit 9004bcd
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions text/0803-type-ascription.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ lvalue position), then we don't have the soundness problem, but we do get the
unexpected result that `&(x: T)` is not in fact a reference to `x`, but a
reference to a temporary copy of `x`.

The proposed solution is that type ascription expressions are rvalues, but
taking a reference of such an expression is forbidden. I.e., type asciption is
forbidden in the following contexts (where `<expr>` is a type ascription
expression):
The proposed solution is that type ascription expressions are lvalues, where
the type ascription expression is in reference context, then we require the
ascribed type to exactly match the type of the expression, i.e., neither

This comment has been minimized.

Copy link
@pnkfelix

pnkfelix Mar 19, 2015

There is, I think, some grammatical problem here that is making it difficult for me to parse this new sentence.

In particular, the sentence ends with "..., then we require ..."; but it is not 100% clear what the precondition for that "then" is.

I suspect what was intended was the text:

The proposed solution is that when a type ascription expression is in reference context, then we require the ascribed type to exactly match the type of the expression, i.e., neither subtyping nor coercion is allowed. These reference contexts are as follows (where <expr> is a type ascription expression):

(Note that I also put back in the parenthetical text explaining what <expr> is...)

Also, do we need to add examples of type ascription being used on the left-hand-side of an assignment, since apparently it would now be allowed? (Perhaps it needs to be added to the list of reference contexts?)

subtyping nor coercion is allowed. These contexts are:

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

Like other rvalues, type ascription would not be allowed as the lhs of assignment.

Note that, if type asciption is required in such a context, an lvalue can be
forced by using `{}`, e.g., write `&mut { foo: T }`, rather than `&mut (foo: T)`.


# Drawbacks

More syntax, another feature in the language.
Expand Down

0 comments on commit 9004bcd

Please sign in to comment.