Skip to content

Close the set of traits accepted by generate_trait_thunks#1469

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

Close the set of traits accepted by generate_trait_thunks#1469
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_951030364

Conversation

@copybara-service

Copy link
Copy Markdown

Close the set of traits accepted by generate_trait_thunks

This CL adds SupportedTrait, which means that generate_trait_thunks will not work for just any trait anymore. This is particularly useful for upcoming opaque types like compiler generated types, because often times they cannot be spelled out like regular types. For example without this, I was running into issues in some followups where it would try to format the param to Drop::drop as &mut impl Future<...>, since we were creating substs and then a FnSig on a not-fully-revealed opaque type. And we can't fully reveal the opaque type, because sometimes we can't spell it like if it's the future from an async fn.

By controlling the set of functions we support for now, we can carefully construct the correct signatures for each trait to handle opaques correctly. For example, the extern C signature of Drop::drop of an opaque should just erase the type of the pointer completely, and then use the fn inner<F: FnOnce() -> T>(_: F, erased: *mut ()) trick to bind the anonymous type to T.

@google-cla

google-cla Bot commented Jul 20, 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 force-pushed the test_951030364 branch 2 times, most recently from 190bd4b to 3a26e91 Compare July 21, 2026 15:47
This CL adds `SupportedTrait`, which means that `generate_trait_thunks` will not work for just any trait anymore. This is particularly useful for upcoming opaque types like compiler generated types, because often times they cannot be spelled out like regular types. For example without this, I was running into issues in some followups where it would try to format the param to `Drop::drop` as `&mut impl Future<...>`, since we were creating `substs` and then a `FnSig` on a not-fully-revealed opaque type. And we can't fully reveal the opaque type, because sometimes we can't spell it like if it's the future from an async fn.

By controlling the set of functions we support for now, we can carefully construct the correct signatures for each trait to handle opaques correctly. For example, the extern C signature of `Drop::drop` of an opaque should just erase the type of the pointer completely, and then use the `fn inner<F: FnOnce() -> T>(_: F, erased: *mut ())` trick to bind the anonymous type to `T`.

PiperOrigin-RevId: 951030364
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