Skip to content

codegen: support a custom repeated_type in lazy to_owned_message - #803

Open
v0ropaev wants to merge 1 commit into
anthropics:mainfrom
v0ropaev:fix/lazy-view-custom-repeated
Open

v0ropaev wants to merge 1 commit into
anthropics:mainfrom
v0ropaev:fix/lazy-view-custom-repeated

Conversation

@v0ropaev

@v0ropaev v0ropaev commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

With lazy_views(true) and repeated_type_custom, a crate with a repeated message field does not compile. The lazy to_owned_message collects the decoded elements into a Vec and returns it as the field value, but the owned struct holds the custom collection.

error[E0308]: mismatched types
   --> .../out/repeated_type.__lazy_view.rs:205:17
205 |                 __out
    |                 ^^^^^ expected `CustomList<Inner>`, found `Vec<Inner>`

I hit it with a small crate that compiles one proto with repeated_type_custom("crate::CustomList<*>") and turns codegen options on one at a time. With only lazy_views(true) added it fails as above. The eager view path already collects into the custom type, so only the lazy path was missing it.

The fix sends the Vec through the collection's From<Vec<T>>, which ProtoList already requires. For the default Vec the generated code stays exactly as it was, so it doesn't trip clippy::useless_conversion in user crates, and no checked-in generated code changes.

The existing repeated_type fixture in buffa-test now also builds lazy views, and lazy_view_to_owned_round_trip does a decode_lazy then to_owned_message round trip on the sample message. A codegen test, lazy_to_owned_converts_vec_only_for_custom_collection, checks that the conversion is emitted for a custom collection and not for Vec. On main the fixture fails with the E0308 above and the codegen test fails its assertion.

fmt and clippy with -D warnings are clean on buffa-codegen and buffa-test (and on buffa-test with --features arbitrary), and both test suites pass on 1.95.0.

While testing this I also noticed repeated_type_custom breaks text generation. That one is #802.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

With lazy_views(true) and repeated_type_custom, the lazy to_owned_message
built a repeated message field in a Vec and returned it where the owned
struct holds the custom collection, so the generated crate failed with
E0308. Pass the Vec through the collection's From<Vec<T>>, which ProtoList
already requires. The default Vec path emits the same code as before, so it
does not trip clippy::useless_conversion.

The repeated_type fixture in buffa-test now also builds lazy views, with a
decode_lazy to to_owned_message round trip, and a codegen test pins that
only the custom collection gets the conversion.
@v0ropaev
v0ropaev force-pushed the fix/lazy-view-custom-repeated branch from 57d3dfd to 66b25e6 Compare October 28, 2026 10:16

This branch has not been deployed

No deployments
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