Repository navigation
Require operator== to bind without errors before implementing PartialOrd - #2924
Closed
copybara-service[bot] wants to merge 1 commit into
Closed
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
When a C++ record defines `operator==` with an unsupported signature (such as returning `int` instead of `bool`) alongside a relational or three-way comparison operator (`<=>`, `<`, `>`, `<=`, `>=`) that returns `bool`, `generate_function` still returns `Ok(Some(GeneratedFunction))` for `operator==` with `status: Err(...)` so it can emit an uncallable `PartialEq` impl with an unsatisfied `where for<'error> &'error (): BindingFailedFor_...` bound. Previously, `BindingsGenerator::get_binding` only checked `generate_function(...).ok().flatten().is_some()`, treating any `Some(GeneratedFunction)` as a valid binding regardless of `status`. As a result, `api_func_shape_for_operator_partial_ord` saw `operator==` as implementing `PartialEq` and emitted an unconditional `impl PartialOrd` calling `self == other`, which failed to compile because the `PartialEq` supertrait bound was unsatisfied. Include `generated_function.status.is_ok()` in the tuple returned by `get_binding`: - `api_func_shape_for_operator_partial_ord` requires `status.is_ok()` (`true`) when checking whether `operator==` implements `PartialEq` (and when checking whether a preferred comparison operator already implements `PartialOrd`). - `api_func_shape_for_operator_ne` continues to skip `operator!=` whenever `operator==` generates a `PartialEq` impl (even with `status.is_err()`), avoiding duplicate `PartialEq::eq` overload collisions in `overload_sets`. PiperOrigin-RevId: 1019163178
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Require operator== to bind without errors before implementing PartialOrd
When a C++ record defines
operator==with an unsupported signature (such as returningintinstead ofbool) alongside a relational or three-way comparison operator (<=>,<,>,<=,>=) that returnsbool,generate_functionstill returnsOk(Some(GeneratedFunction))foroperator==withstatus: Err(...)so it can emit an uncallablePartialEqimpl with an unsatisfiedwhere for<'error> &'error (): BindingFailedFor_...bound.Previously,
BindingsGenerator::get_bindingonly checkedgenerate_function(...).ok().flatten().is_some(), treating anySome(GeneratedFunction)as a valid binding regardless ofstatus. As a result,api_func_shape_for_operator_partial_ordsawoperator==as implementingPartialEqand emitted an unconditionalimpl PartialOrdcallingself == other, which failed to compile because thePartialEqsupertrait bound was unsatisfied.Include
generated_function.status.is_ok()in the tuple returned byget_binding:api_func_shape_for_operator_partial_ordrequiresstatus.is_ok()(true) when checking whetheroperator==implementsPartialEq(and when checking whether a preferred comparison operator already implementsPartialOrd).api_func_shape_for_operator_necontinues to skipoperator!=wheneveroperator==generates aPartialEqimpl (even withstatus.is_err()), avoiding duplicatePartialEq::eqoverload collisions inoverload_sets.