Skip to content

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

Closed

Conversation

leoyvens
Copy link

@leoyvens leoyvens commented Feb 3, 2018

Thanks @nikomatsakis for early feedback! Tracking issue of the previous RFC rust-lang/rust#27336.

Rendered


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postonedpostponed


```rust
fn foo<T=String>(x: Option<T>);
fn bar<U>(y: Option<T>); // What if we had `fn bar<U=usize>`?
Copy link
Member

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?

@leoyvens leoyvens changed the title Default type parameter fallback revisited. Default type parameter fallback revisited Feb 3, 2018
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Feb 3, 2018
@Centril
Copy link
Contributor

Centril commented Feb 3, 2018

I've only done a quick initial reading, but it seems compatible with RFC #2176 (partial turbofish).
If a function definition site has N type parameters and a function application site has M type arguments in turbofish, then before type inference, N - M amount of , _ will be inserted mechanically at the turbofish site. Type inference and any defaults are handled from there on.

@leoyvens
Copy link
Author

leoyvens commented Feb 3, 2018

@Centril Yes this is intended to be compatible with that RFC, see this paragaph:

The behaviour of partially supplied parameter lists is as per RFC 213, omited parameters that have a default are inferred as if filled in with _.

@leoyvens leoyvens force-pushed the default-parameter-fallback-take-two branch from 97e2780 to 8320e56 Compare February 3, 2018 15:36
@Centril
Copy link
Contributor

Centril commented Feb 3, 2018

@leodasvacas Wonderful! Then they don't need to block each other. Might I suggest adding a reference to #2176 in the relevant paragraph? For the roll-out plan, I suggest implementing #2176 first since it's a rather simple change and is a step on the way to this RFC.

@nikomatsakis
Copy link
Contributor

cc @eddyb

@leoyvens leoyvens force-pushed the default-parameter-fallback-take-two branch from 5c164bb to 6226568 Compare February 9, 2018 18:51
@leoyvens leoyvens force-pushed the default-parameter-fallback-take-two branch from 6226568 to 587b9bf Compare February 9, 2018 19:03
@leoyvens
Copy link
Author

@petrochenkov Noticed your confused emoji reaction, would you like to expand on that?

@Ericson2314
Copy link
Contributor

Ericson2314 commented Feb 14, 2018

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.

@petrochenkov
Copy link
Contributor

@leodasvacas
I have same concerns as @Ericson2314 basically.

@leoyvens leoyvens force-pushed the default-parameter-fallback-take-two branch from 1069c50 to 295be8b Compare February 14, 2018 21:09
@leoyvens
Copy link
Author

@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.

@leoyvens leoyvens force-pushed the default-parameter-fallback-take-two branch 5 times, most recently from f40c1b7 to a18e7c1 Compare March 15, 2018 18:32
@leoyvens leoyvens force-pushed the default-parameter-fallback-take-two branch from a18e7c1 to c7171f4 Compare March 15, 2018 18:33
@aturon
Copy link
Member

aturon commented Mar 15, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants