-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Default type parameter fallback revisited #2321
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
Default type parameter fallback revisited #2321
Conversation
|
||
Defaults may be set for type parameters in in traits, impls, struct and enum definitions and also methods and fns. They may not be set in `type` aliases. They also may not be set in methods and associated fns of trait impls, such defaults can only be set in the trait declaration. As per RFC 213, parameters with defaults must be trailing and may not be forward declared. | ||
|
||
The behaviour of omited parameters in partially supplied parameter lists is as per RFC 213, they are inferred as if filled in with `_`. This is relevant to this [postoned RFC](https://github.com/rust-lang/rfcs/pull/1196) that suggests extending that behaviour to non-defaulted parameters. |
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.
postoned
↦ postponed
|
||
```rust | ||
fn foo<T=String>(x: Option<T>); | ||
fn bar<U>(y: Option<T>); // What if we had `fn bar<U=usize>`? |
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.
Do you mean y: Option<U>
here?
I've only done a quick initial reading, but it seems compatible with RFC #2176 (partial turbofish). |
@Centril Yes this is intended to be compatible with that RFC, see this paragaph:
|
97e2780
to
8320e56
Compare
I don't think it makes much sense really.
cc @eddyb |
5c164bb
to
6226568
Compare
6226568
to
587b9bf
Compare
@petrochenkov Noticed your confused emoji reaction, would you like to expand on that? |
The reference explanation is still somewhat guide-y and missing some precision. I'm having a hard time understanding how the concerns from before about multiple defaults are mitigated, for example. +1 on the basic idea/goals though. |
@leodasvacas |
1069c50
to
295be8b
Compare
@Ericson2314 @petrochenkov The algorithm for applying fallback remains the one specified in RFC 213 modulo some considerations that I've added to this RFC. This RFC accepts that the algorithm fails on conflicting fallbacks and tries to mitigate that by documenting the practical implications to API evolution and proposing default elision, but there is no mitigation in the algorithm itself. |
f40c1b7
to
a18e7c1
Compare
a18e7c1
to
c7171f4
Compare
Note that @Centril, @leodasvacas and some others are now taking up discussion related to default type parameters on functions, turbofish, and more -- hopefully resulting in a new RFC. As such, I'm going to close this one for the time being. |
Thanks @nikomatsakis for early feedback! Tracking issue of the previous RFC rust-lang/rust#27336.
Rendered