Skip to content

Require operator== to bind without errors before implementing PartialOrd - #2924

Closed
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1019163178
Closed

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1019163178

Conversation

@copybara-service

Copy link
Copy Markdown

Require operator== to bind without errors before implementing PartialOrd

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.

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
@google-cla

google-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

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.

@copybara-service copybara-service Bot closed this Nov 12, 2026
@copybara-service
copybara-service Bot deleted the test_1019163178 branch November 12, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants