-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Permit impl methods whose bounds cannot be satisfied to have no body #20021
Copy link
Copy link
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.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-trait-systemArea: Trait systemArea: Trait systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.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.
There is a curious case with where clauses where sometimes we can show that a method in an impl could not possibly be called. This is because the impl has more precise information than the trait. Here is an example:
We should permit the method body to be omitted in such a case. As a workaround, once #20020 is fixed, I imagine it would be possible to write an impl like this:
However, it is unfortunate to require that of the user. For one thing, perhaps it happens later that an impl of
Eqis added forBar-- now we have this method hanging around that will panic. It'd be nice to detect that statically.The plan then would be to permit:
This serves as a declaration that you believe this method could never be called. At trans time, we will generate a body that simply does the equivalent of
panic!("unsatisfiable methodmethodinvoked").I plan to open an amendment to the where clause RFC describing this particular case.