Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement type ascription. #21836

Closed
wants to merge 1 commit into from
Closed

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Feb 1, 2015

First iteration of type ascription in expressions. Syntax is expr: T with the same precedence as as.
Shouldn't be backwards incompatible, but I've had to modify asm! to not include colons in parsing.

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member Author

eddyb commented Feb 1, 2015

@SiegeLord had challenged me to this, and I will not be making a RFC myself as I've already spent more than the ten minutes I've allocated for it.
Anyone else is welcome to do so. cc @nikomatsakis

@japaric
Copy link
Member

japaric commented Feb 1, 2015

cc @nick29581

@nrc
Copy link
Member

nrc commented Feb 2, 2015

I don't see any reason not to land this soon. But we should wait for an RFC first, I'll chat to Niko about priorities and can write one up if we decide to go for it.

@nikomatsakis
Copy link
Contributor

+1

@nrc
Copy link
Member

nrc commented Feb 3, 2015

RFC: rust-lang/rfcs#803

@alexcrichton
Copy link
Member

Closing in favor of the associated RFC

@eddyb
Copy link
Member Author

eddyb commented Feb 24, 2015

@alexcrichton I don't understand - all of my changes are still necessary - is a complete RFC implementation expected in case of approval?

@huonw
Copy link
Member

huonw commented Feb 24, 2015

Patches for major* features like this don't land until there's more consensus about the RFC.

(*whether a feature is major or not is independent of the difficult of implementation.)

@eddyb
Copy link
Member Author

eddyb commented Feb 24, 2015

Is then "in favor of" supposed to mean "pending resolution of"? That is fine with me.

@alexcrichton
Copy link
Member

Yes sorry I'm just trying to keep the queue size down, it's fine to reopen this once the RFC is accepted.

@Ryman
Copy link
Contributor

Ryman commented Mar 26, 2015

RFC was accepted, should this be reopened? cc #23416

@eddyb
Copy link
Member Author

eddyb commented Mar 26, 2015

@Ryman needs a rebase and I was waiting on @nrc to merge #23630, but I guess there's nothing stopping me now, not really. Shouldn't interfere with DST work, which was my main concern.

@ticki
Copy link
Contributor

ticki commented Nov 20, 2015

What's the state of this? The opinion about type ascription seems to be positive overall.

@jroesch
Copy link
Member

jroesch commented Dec 15, 2015

Overall looks good, I feel like a name like ExprAscribe (or something else) would be better, it wasn't clear to me that ExprType corresponds to type ascription when reading the code. I'm happy to r+ this if no one else has an issue.

@eddyb
Copy link
Member Author

eddyb commented Dec 15, 2015

@jroesch There are several newer rebase attempts.

bors added a commit that referenced this pull request Dec 19, 2015
This PR is a rebase of the original PR by @eddyb #21836 with some unrebasable parts manually reapplied, feature gate added + type equality restriction added as described below.

This implementation is partial because the type equality restriction is applied to all type ascription expressions and not only those in lvalue contexts. Thus, all difficulties with detection of these contexts and translation of coercions having effect in runtime are avoided.
So, you can't write things with coercions like `let slice = &[1, 2, 3]: &[u8];`. It obviously makes type ascription less useful than it should be, but it's still much more useful than not having type ascription at all.
In particular, things like `let v = something.iter().collect(): Vec<_>;` and `let u = t.into(): U;` work as expected and I'm pretty happy with these improvements alone.

Part of #23416
@jroesch
Copy link
Member

jroesch commented Dec 31, 2015

@eddyb makes sense, this is a pretty straight forward thing to implement.

@nikomatsakis
Copy link
Contributor

(Note that this has now been implemented in #30184, but without the coercion aspect.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.