-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: boxed oneof field #1210
base: master
Are you sure you want to change the base?
fix: boxed oneof field #1210
Conversation
fix tokio-rs#1159 Signed-off-by: xxchan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test will pass without the other changes. CodeGenerator
already makes the OneOf field a Box<T>
if self.boxed() == true
on line 667.
Can you explain why the other changes are needed?
prost-derive/src/field/oneof.rs
Outdated
@@ -15,6 +15,8 @@ impl Field { | |||
pub fn new(attrs: &[Meta]) -> Result<Option<Field>, Error> { | |||
let mut ty = None; | |||
let mut tags = None; | |||
let mut boxed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where this variable is used. Can you explain what this does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I see some unknown attribute
error while developing, so I copied the code from message.rs
.
https://github.com/xxchan/prost/blob/56b96023a17a0b15026fedc63ec9a5ea8b128ddf/prost-derive/src/field/message.rs#L26-L27
But you are right, this seems to a unnecessary mistake.
Signed-off-by: xxchan <[email protected]>
Signed-off-by: xxchan <[email protected]>
Signed-off-by: xxchan <[email protected]>
Signed-off-by: xxchan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @caspermeijn, thanks for the prompt review! Reverted unnecessary changes, and made CI Green.
I think this test will pass without the other changes.
I'm not sure what you mean by "other changes" here.
But anyway, here's how it works:
As mentioned in #1159, the type for the oneof field was correct. What was wrong is the generated merge
function.
I noticed there are #[prost(boxed)]
on normal messages fields, but not on the oneof
field. After adding it, it works.
pub struct Foo {
#[prost(message, optional, boxed, tag = "1")]
pub bar: ::core::option::Option<::prost::alloc::boxed::Box<Bar>>,
#[prost(oneof = "foo::OneofField", tags = "2, 3")]
pub oneof_field: ::core::option::Option<foo::OneofField>,
}
/// Nested message and enum types in `Foo`.
pub mod foo {
pub enum OneofField {
#[prost(string, tag = "2")]
Baz(::prost::alloc::string::String),
// This PR added "boxed" here
#[prost(message, boxed, tag = "3")]
BoxQux(::prost::alloc::boxed::Box<super::Bar>),
}
}
prost-derive/src/field/oneof.rs
Outdated
@@ -15,6 +15,8 @@ impl Field { | |||
pub fn new(attrs: &[Meta]) -> Result<Option<Field>, Error> { | |||
let mut ty = None; | |||
let mut tags = None; | |||
let mut boxed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I see some unknown attribute
error while developing, so I copied the code from message.rs
.
https://github.com/xxchan/prost/blob/56b96023a17a0b15026fedc63ec9a5ea8b128ddf/prost-derive/src/field/message.rs#L26-L27
But you are right, this seems to a unnecessary mistake.
fix #1159
Signed-off-by: xxchan [email protected]