Skip to content

Add support for operation traits for references. - #1998

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_979856777
Sep 16, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
test_979856777

Conversation

@copybara-service

Copy link
Copy Markdown

Add support for operation traits for references.

Before this fix impl core::ops::OP<&T> for &T wouldn't generate any C++ bindings, which is annoying because, e.g., a & b won't work without the Copy trait.
The lack of reference support also means an extra copy for performance critical
stuff if a free function operator is manually added in C++ (although,
one can work around this by creating a helper method in rust).

If both implementations (for T and for &T) are implemented, only the
non-ref one will be generated for backwards compatibility, albeit the
one with the reference might be the more desirable.

copybara-service Bot pushed a commit to google/safe-bindings that referenced this pull request Sep 15, 2026
This speeds up the operator calls my multiple x's.

Crubit doesn't support creating bindings for operators for a reference
implementation type (`for &T`), which is why helper methods are
required. This can be refactored if [1] lands.

[1] google/crubit#1998

PiperOrigin-RevId: 980627043
copybara-service Bot pushed a commit to google/safe-bindings that referenced this pull request Sep 15, 2026
This speeds up the operator calls my multiple x's.

Crubit doesn't support creating bindings for operators for a reference
implementation type (`for &T`), which is why helper methods are
required. This can be refactored if [1] lands.

[1] google/crubit#1998

PiperOrigin-RevId: 980627043
copybara-service Bot pushed a commit to google/safe-bindings that referenced this pull request Sep 15, 2026
This speeds up the operator calls my multiple x's.

Crubit doesn't support creating bindings for operators for a reference
implementation type (`for &T`), which is why helper methods are
required. This can be refactored if [1] lands.

[1] google/crubit#1998

PiperOrigin-RevId: 981791594
@copybara-service
copybara-service Bot force-pushed the test_979856777 branch 3 times, most recently from 81b7909 to 58a4af1 Compare September 16, 2026 07:05
Before this fix `impl core::ops::OP<&T> for &T` wouldn't generate any C++ bindings, which is annoying because, e.g., `a & b` won't work without the `Copy` trait.
The lack of reference support also means an extra copy for performance critical
stuff if a free function operator is manually added in C++ (although,
one can work around this by creating a helper method in rust).

If both implementations (`for T` and `for &T`) are implemented, only the
non-ref one will be generated for backwards compatibility, albeit the
one with the reference might be the more desirable.

PiperOrigin-RevId: 982326607
@copybara-service
copybara-service Bot merged commit 253ee91 into main Sep 16, 2026
1 check passed
@copybara-service
copybara-service Bot deleted the test_979856777 branch September 16, 2026 07:38
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.

1 participant