Skip to content

rs_bindings_from_cc: fix bindings for inherited static member functions. - #2047

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_983387807
Sep 18, 2026
Merged

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

Conversation

@copybara-service

Copy link
Copy Markdown

rs_bindings_from_cc: fix bindings for inherited static member functions.

Derived classes inherit static member functions, but the bindings generated for
the derived class rewrote the type of the first parameter to Self. That
rewrite models the implicit this pointer, so it is only correct for instance
methods. When a static member function has a first parameter naming the
enclosing class, the derived class declared that parameter with the derived
type while the wrapper it forwards to still expected the base type, and the
generated crate failed to compile. A static member function taking two such
parameters was also rewritten asymmetrically, changing only the first one.

Gate the rewrite on Func::is_instance_method, the condition already used to
decide whether the first parameter is formatted as self. Derived::f now
takes a Base argument, matching C++, where a static member function reached
through a derived class still accepts a base class argument.

@copybara-service
copybara-service Bot force-pushed the test_983387807 branch 2 times, most recently from e6ade87 to 46d65cc Compare September 18, 2026 02:25
Derived classes inherit static member functions, but the bindings generated for
the derived class rewrote the type of the first parameter to `Self`. That
rewrite models the implicit `this` pointer, so it is only correct for instance
methods. When a static member function has a first parameter naming the
enclosing class, the derived class declared that parameter with the derived
type while the wrapper it forwards to still expected the base type, and the
generated crate failed to compile. A static member function taking two such
parameters was also rewritten asymmetrically, changing only the first one.

Gate the rewrite on `Func::is_instance_method`, the condition already used to
decide whether the first parameter is formatted as `self`. `Derived::f` now
takes a `Base` argument, matching C++, where a static member function reached
through a derived class still accepts a base class argument.

PiperOrigin-RevId: 983572212
@copybara-service
copybara-service Bot merged commit cfb6d62 into main Sep 18, 2026
1 check passed
@copybara-service
copybara-service Bot deleted the test_983387807 branch September 18, 2026 02:44
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