-
Notifications
You must be signed in to change notification settings - Fork 0
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
impl Trait
in Traits
#3
Comments
I spoke with @aturon about this, and they're really emphasizing this part of the proposal. In the interest of making progress on this, I'd like to start exploring what exactly each of these features should do.
|
Interesting points. I had never considered "interpretation B" -- it still seems strikingly less useful to me, but I agree that Basically interpretation B is tailored for "combinator"-style traits (iterator, parsing combinators, that sort of thing), which are certainly common. |
On a related note, I have mixed feelings about the pattern where all the combinator methods are defined in the trait itself, to be honest. I think the main reason we do it this way is because it's sort of "seems" simple, and it looks good in rustdoc, but it has some surprising effects: Implementing types have some freedom to override, but not much. If I have some better way of implementing It doesn't play that great with objects. To make the trait object safe, we had to add various Originally I sort of preferred the idea of having the But, water under the bridge, probably, and I don't really want to add final functions per se. =) Anyway, I guess it's just something to think about. |
A major motivation for this is making However, its often the case that we do care about things like |
If you ignore trait objects, then there isn't much of a reason to adopt the first interpretation -- where (Really it would desugar into an associated type that is tied to the particular implementation in a way that you can't normally do. In other words, trait Foo {
// in place of `fn foo() -> impl Bar { ... }`
type FooRet: Bar;
fn foo() -> Self::FooRet;
}
default impt<T: Foo> Foo<T> {
default {
type FooRet = XXX;
fn foo(&self) -> XXX { ... }
}
} Here the "inner" It's sort of interesting because, in the case of the |
I wrote up my thoughts on an early draft RFC on this topic here. |
I personally don't like the idea of having impl trait in trait prototype. I don't like it either in argument position. but for some reason this gets added to stable, I can more use cases for interpretation B. |
Edit: A draft RFC for this feature was written. Linking here for visibility.
This is really two separate but related features:
impl Trait
in trait definitions, andimpl Trait
in trait implementations:A proposal on this front should address the following issues:
impl Trait
-returning impl.impl Trait
in a trait object.@nikomatsakis suggested the possibility of inferring associated types based on the definitions of other items.
The text was updated successfully, but these errors were encountered: