Add support for operation traits for references. - #1998
Merged
Merged
Conversation
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
Bot
force-pushed
the
test_979856777
branch
3 times, most recently
from
September 16, 2026 07:05
81b7909 to
58a4af1
Compare
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
Bot
force-pushed
the
test_979856777
branch
from
September 16, 2026 07:38
58a4af1 to
253ee91
Compare
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.
Add support for operation traits for references.
Before this fix
impl core::ops::OP<&T> for &Twouldn't generate any C++ bindings, which is annoying because, e.g.,a & bwon't work without theCopytrait.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 Tandfor &T) are implemented, only thenon-ref one will be generated for backwards compatibility, albeit the
one with the reference might be the more desirable.