Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPartially implement type ascription #30184
Conversation
This comment has been minimized.
This comment has been minimized.
|
Hm, @rust-highfive failed to assign a reviewer. r? @eddyb |
rust-highfive
assigned
eddyb
Dec 3, 2015
This comment has been minimized.
This comment has been minimized.
|
I wrote the original version of this code, so I'd rather have someone else look over it. |
rust-highfive
assigned
nikomatsakis
and unassigned
eddyb
Dec 3, 2015
oli-obk
reviewed
Dec 3, 2015
| @@ -2671,6 +2671,14 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, | |||
| } | |||
| } | |||
|
|
|||
| fn check_expr_eq_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, | |||
| expr: &'tcx hir::Expr, | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov
force-pushed the
petrochenkov:ascr
branch
from
8fd1579
to
96d2791
Dec 4, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
This comment has been minimized.
This comment has been minimized.
|
|
eddyb
and others
added some commits
Feb 1, 2015
petrochenkov
force-pushed the
petrochenkov:ascr
branch
from
96d2791
to
7afc5e2
Dec 16, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
This comment has been minimized.
This comment has been minimized.
|
Sorry for the delay! I'll get to this soon. |
nikomatsakis
reviewed
Dec 18, 2015
| @@ -320,6 +320,8 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { | |||
| name: Field::new(index.node as usize) }, | |||
| hir::ExprCast(ref source, _) => | |||
| ExprKind::Cast { source: source.to_ref() }, | |||
| hir::ExprType(ref source, _) => | |||
| return source.make_mirror(cx), | |||
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Dec 18, 2015
Contributor
This doesn't seem right. I think we probably want to convert this to a ExprKind::Cast.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Dec 18, 2015
Contributor
/me reconsiders. Actually, let me read a bit more and get back to this point!
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov I didn't notice at first that you skipped over the coercion aspect. Makes sense for a first pass, this certainly simplifies things. The code looks great. The only thing I would want to add are some parsing tests that test the relative precedence of |
This comment has been minimized.
This comment has been minimized.
|
Some examples tests for precedence:
The only tricky part is how to write such at est. I envisioned testing this by setting up some scenarios that will fail to type-check if the precedence is not correct? I'm not sure if there is a better way. |
This comment has been minimized.
This comment has been minimized.
Thanks! In fact my free time is coming to an end rapidly, so I have to wrap up my work on rustc ASAP (at least for now). |
This comment has been minimized.
This comment has been minimized.
:( Let me know if there is work you think you will not have time for! I'd be happy to land this PR (or privacy) and then do the followup work myself. |
petrochenkov
force-pushed the
petrochenkov:ascr
branch
from
7afc5e2
to
95fdaf2
Dec 18, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated with the operator precedence tests. |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ Another nice PR. Thanks @petrochenkov! |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Dec 19, 2015
This comment has been minimized.
This comment has been minimized.
bors
merged commit 95fdaf2
into
rust-lang:master
Dec 19, 2015
This comment has been minimized.
This comment has been minimized.
|
This should probably be marked with |
petrochenkov commentedDec 3, 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<_>;andlet u = t.into(): U;work as expected and I'm pretty happy with these improvements alone.Part of #23416