-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Generalized Type Ascription #2522
RFC: Generalized Type Ascription #2522
Conversation
…nctions + readability.
That still would not allow pub trait Is<T> {}
impl<T> Is<T> for T {}
pub trait HackyIdentity: Sized {
fn identity<T>(self) -> Self where Self: Is<T> {
self
}
}
impl<T> HackyIdentity for T {} |
I still prefer generalized ascription, but one alternative that solves part of the motivation of this issue might be to allow turbofish to be used for trait methods. For example something like this (syntax is bikeshedable): trait Bar {
fn bar<T, U, V>(args: (T, U, V));
}
foo.bar::<as Bar, T, U, V>(args); |
I'm interested in this RFC, what is the status? It's been 4 months since last comment. |
rfcbot's last comment is now hidden under the fold: There are five concerns currently marked as unresolved. |
(Checking @aturon's box, as he's no longer on the lang team.) |
@rfcbot fcp cancel I'm going to cancel the FCP on this issue because it's very old. In fact, I'm planning to close this RFC as "postponed". The feature described within still seems potentially desirable, but it's clear that there is plenty of follow-up work to do. I would like to encourage anyone who wants to pursue this design to try and do so through the new, experimental lang-team MCP process described in RFC #2936. One other thought is that it is likely possible to extract some subset of the functionality described in this RFC and move that forward rather than trying to do all the work at once. |
@nikomatsakis proposal cancelled. |
As stated above, I'm also going to close this RFC as "postponed" -- if you'd like to pick up activity here, please do reach out on Zulip or consider opening an MCP, and we can discuss whether there is a good candidate to serve as an active liaison. Thanks. ❤️ |
I ran into this problem and posted a SO question about it regarding variable ascription in for loops. FWIW, I wrote in the question:
|
🖼️ Rendered
📝 Summary
This RFC supersedes and subsumes RFC 803. It generalizes existing type ascription in
let
bindings to everywhere a pattern can occur and makes some changes to ascription in expressions. You may now for example write:Here, the underlined bits are patterns.
Finally, when a user writes
Foo { $field: $pat : $type }
, and when$pat
and$type
are syntactically α-equivalent, the compiler emits a warn-by-default lint suggesting:Foo { $field: ($pat : $type) }
.💖 Thanks
To @nrc, @kennytm, @varkor for reviewing the draft version.
To @scottmcm in particular for reviewing and being my rubber duck wrt. type inference.
Edit: Direct link to the pFCP checkboxes: #2522 (comment)