-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Type and const parameters are not used as a fallback during type inference #98931
Copy link
Copy link
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Currently you're able to define default const parameters for a type. This is explained here. This allows one to write generic
implblocks but requires some explicit type coercion as shown in this stack-overflow article on thenewconstructor.It would be great if rust can infer that the type has to be the return type of the
newconstructor and, if the const parameter is not provided, infer that the type defaults to the default const value.The stack-overflow article had me confused for a bit (see this reddit post) so I'll provide a more explicit example:
I expected to see this happen:
Successfully infer that the type has to be the default const variant of the type.
Instead, this happened:
Clarity
To be clear, the following works:
but this does not:
On the face of it the above looks silly.
Meta
Bug is also present on
nightly.