-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Partially implement type ascription #30184
Conversation
Hm, @rust-highfive failed to assign a reviewer. r? @eddyb |
I wrote the original version of this code, so I'd rather have someone else look over it. |
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation
☔ The latest upstream changes (presumably #29850) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
☔ The latest upstream changes (presumably #30206) made this pull request unmergeable. Please resolve the merge conflicts. |
+ Apply parser changes manually + Add feature gate
Rebased. |
Sorry for the delay! I'll get to this soon. |
@@ -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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right. I think we probably want to convert this to a ExprKind::Cast
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/me reconsiders. Actually, let me read a bit more and get back to this point!
@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 |
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. |
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). |
:( 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. |
+ Rebase fixes
Updated with the operator precedence tests. |
@bors r+ Another nice PR. Thanks @petrochenkov! |
📌 Commit 95fdaf2 has been approved by |
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
This should probably be marked with |
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