-
Notifications
You must be signed in to change notification settings - Fork 526
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 string field #1210
base: master
Are you sure you want to change the base?
fix: boxed string 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?
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>),
}
}
When I only apply the changes in This means that either your tests are incomplete or that the code changes in |
cfg_if! { | ||
if #[cfg(feature = "edition-2015")] { | ||
use boxed_field::foo::OneofField; | ||
} else { | ||
use foo::OneofField; | ||
} | ||
} | ||
|
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.
You could simplify this to:
cfg_if! { | |
if #[cfg(feature = "edition-2015")] { | |
use boxed_field::foo::OneofField; | |
} else { | |
use foo::OneofField; | |
} | |
} | |
use self::foo::OneofField; |
Yes you are right. I found the problem is only for
|
But it seems not useful at all to |
I agree, a Perhaps it should just ignore To improve the tests, you could try to reuse |
fix #1159
Signed-off-by: xxchan [email protected]