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

Default type parameters are not in the language reference #38011

Closed
diwic opened this issue Nov 26, 2016 · 3 comments
Closed

Default type parameters are not in the language reference #38011

diwic opened this issue Nov 26, 2016 · 3 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@diwic
Copy link
Contributor

diwic commented Nov 26, 2016

Default type parameters (e g struct Foo<A = u32>(A)) is a language feature, but they are not mentioned in the language reference.

It would be nice if such a reference also mentioned the tricky semantics around how it interacts with inference, as mentioned here.

@bluss
Copy link
Member

bluss commented Nov 26, 2016

Type parameter defaults are syntactical at the moment and don't really interact with inference.

The linked issue is basically that given Test::<>::default() I expected that to be equivalent to <Test<>>::default() but it is equivalent to <Test<_, _>>::default()

@diwic
Copy link
Contributor Author

diwic commented Nov 26, 2016

Maybe it's a bit poorly phrased, what I meant was something like, if you change Test::<u32> to Test::<u32,_>, then you disable default type parameters and enable inference (?). And to enable default type parameters in the first place you need either the <Test> syntax (which I hadn't seen before today), or Test::<_>, but the latter is impossible to use for the first default type parameter (given the linked issue).

All this might be a poor layman's explanation, which is the reason I filed the bug in the hope of getting a better one :-)

Side note: What would have been more intuitive to me, would be an algorithm like:

  1. If the type parameter is explicitly mentioned (i e Test<u32, &str>), use that
  2. else if inference can find out the correct type, use that
  3. else if there is a default type parameter, use that
  4. else give a compiler error.

...i e, that they would interact more than they do today. But that's a bigger question (and one the might be hard to do in a backwards compatible fashion, I don't know).

@bluss bluss added the A-docs label Nov 26, 2016
@steveklabnik steveklabnik removed the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Mar 10, 2017
@steveklabnik steveklabnik added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Mar 23, 2017
@steveklabnik
Copy link
Member

The reference lives in its own repository now, I've moved it to rust-lang/reference#24

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

No branches or pull requests

3 participants