Add an option to box oneof fields of kind message #420
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.
Currently,
protoc-rust
cannot handle mutually recursive messages with oneofs, even withsingular_field_option_box
enabled. For instance, the exampleproduces Rust code whose compilation fails with
For recursive messages that do not go through other messages in the recursive cycle, this problem has been fixed by an ad-hoc check to detect these messages and adding
Box
es where necessary:rust-protobuf/protobuf-codegen/src/oneof.rs
Line 35 in 0674fbb
Unfortunately, this recursion detection does not easily extend to mutually recursive messages.
This PR proposes to solve the problem by allowing the user to specify when oneof fields should be boxed. Therefore, we introduce an option
oneof_field_box
that works likesingular_field_option_box
but on oneof fields of kind message. Fortunately, the infrastructure for doing the boxing/unboxing has already been implemented for the existing ad-hoc recursion check. Thus, we only need to pass the option into the right place and add a few tests.This change is