You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
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:
If the type parameter is explicitly mentioned (i e Test<u32, &str>), use that
else if inference can find out the correct type, use that
else if there is a default type parameter, use that
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).
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
added
the
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
label
Mar 23, 2017
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.
The text was updated successfully, but these errors were encountered: