Skip to content
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

Conditional Bounds #5

Open
cramertj opened this issue Jun 5, 2017 · 2 comments
Open

Conditional Bounds #5

cramertj opened this issue Jun 5, 2017 · 2 comments

Comments

@cramertj
Copy link
Owner

cramertj commented Jun 5, 2017

The ability to specify that an impl Trait return type only implements a trait if some other bound is met.

trait Foo {
   fn foo<T>(x: T) -> impl Debug + (Clone iff T: Clone);
}

As @Kimundi observed in the original impl Trait proposal, this common pattern can be seen in Rust's Iterator trait. Methods like chain return a type that is only Clone if Self: Clone and Other: Clone.

There's some discussion of this in the expanded impl Trait RFC, but I haven't seen any fully-fledged proposals for this yet.

@withoutboats
Copy link

withoutboats commented Jun 9, 2017

This is sort of an orthogonal feature, in that would be implemented for arbitrary bounds, for example, one could imagine:

fn foo<T>() where T: Foo, (T::Assoc: Clone => T: Clone)

Why have you marked this essential? To me it doesn't seem as high priority as #3 for example. Interested in hearing your reasoning!

@cramertj
Copy link
Owner Author

@withoutboats The only issues I've marked as essential are this issue and the one for "fully-explicit syntax". My reasoning was that all the other issues (e.g. #3) don't add anything to the overall expressiveness of the language, and can be mostly thought as sugar for the fully-explicit syntax (#1).

That said, @aturon and I spoke and agreed that #3 is very high-priority. I'll put together a PR against this repo for a pre-draft RFC so we can discuss in more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants