-
Notifications
You must be signed in to change notification settings - Fork 48
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
Positional Associated Types #126
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. |
@rustbot second I'm willing to be the liaison for this. |
Summary of the current state of this: some folks on the lang team have concerns about this, but they're not blocking concerns, and those same folks have explicitly said they don't object to experimentation on nightly, as long as we carefully evaluate those concerns after we have something to experiment. @pnkfelix plans to provide more detail on those concerns. |
I have to focus on school for another couple of weeks but then I'd be thrilled to throw a prototype together in rustc. |
While I have felt the pain of wishing for a shorthand like (That said, I am also skeptical of the motivation, or at least one motivation I have heard: specifically, I don't think that having generators have a return type like I don't see this concern as blocking exploration, but I wanted to note it down, and I would expect to spend some time discussing it before we moved to any sort of RFC here. |
Summary of concerns gathered from lang team meeting on 2021-11-16 and from the zulip thread:
However, it is important to stress that that this is a proposal to solve a problem, not a commitment to a specific solution. The syntax could change, which might address some of the concerns above. In that spirit, here is a list of alternative solutions suggested in Zulip thread:
|
@pnkfelix Great summary, thank you! |
@samsartor When you're ready to start experimenting on this, please take a look at the summary from @pnkfelix, and talk a bit about what approach you want to try to resolve these open questions. |
@joshtriplett Thanks for the ping! Experimentation wise, the I think the difficulty there would be collecting meaningful feedback, so we can actually make progress on resolving the tradeoffs here. Assuming I get some experimental branches done pretty soon, what do you think the next steps should be? Is the goal to write a blog post with concrete examples, or just let this feature flag simmer on nightly until people collectively develop an opinion? |
Following up on this: we can work with a researcher that @nikomatsakis has arranged to try to come up with criteria and process to evaluate this. |
Hey folks! I'm going to close this issue, but I wanted to note that -- per our new process -- this might be a great candidate for a lang-team experiment. I myself remain a bit conflicted here -- I recognize that the current associated type syntax can be ponderous, while being nervous that having more options will lead to more confusion (plus we would now need a style guideline for whether to use the default and when...). |
Positional Associated Types
Proposal
Summary and problem statement
It should be possible to abbreviate
Future<Output=T>
asFuture<T>
.Motivation, use-cases, and solution sketches
Many of the most-used traits in the rust programming language specify a single associated type:
Iterator<Item=T>
Future<Output=T>
FromStr<Err=T>
Deref<Target=T>
Stream<Item=T>
The
impl Trait
syntax is intended to make instances of such traits easy to pass and return. But this can be quite verbose in practice, because each of these traits must be written with the associated type explicitly spelled out:Worse, it may not be clear to incoming Rust programmers why they have to write
Iterator<Item=f32>
instead ofIterator<f32>
. After all, the generics of traits likeFrom<T>
and types likeOption<T>
are not named. It can take many months for the difference between generic parameters and associated types to click, and in that time users probably guess at random which they should use for any given trait.It is worth investigating whether these common cases can be abbreviated:
This should also apply to the
dyn Future<T>
andF: Future<T>
syntaxes.The
Iterator<T>
andFuture<T>
traits would almost certainly be the first to have positional associated types (PATs) stabilized. But the feature could also be beneficial for some traits with multiple associated types:Note this proposal would not immediately include any of the following use cases:
Links and related work
Fut
alias traitInitial people involved
What happens now?
This issue is part of the lang-team initiative process. Once this issue is filed, a Zulip topic will be opened for discussion, and the lang-team will review open proposals in its weekly triage meetings. You should receive feedback within a week or two.
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: