diff --git a/prost-build/src/context.rs b/prost-build/src/context.rs index 6a4d2bcaa..f4dee041b 100644 --- a/prost-build/src/context.rs +++ b/prost-build/src/context.rs @@ -141,10 +141,12 @@ impl<'a> Context<'a> { oneof: Option<&str>, field: &FieldDescriptorProto, ) -> bool { - let repeated = field.label() == Label::Repeated; + if field.label() == Label::Repeated { + // Repeated field are stored in Vec, therefore it is already heap allocated + return false; + } let fd_type = field.r#type(); - if !repeated - && (fd_type == Type::Message || fd_type == Type::Group) + if (fd_type == Type::Message || fd_type == Type::Group) && self .message_graph .is_nested(field.type_name(), fq_message_name) @@ -161,13 +163,6 @@ impl<'a> Context<'a> { .get_first_field(&config_path, field.name()) .is_some() { - if repeated { - println!( - "cargo:warning=\ - Field X is repeated and manually marked as boxed. \ - This is deprecated and support will be removed in a later release" - ); - } return true; } false diff --git a/tests/build.rs b/tests/build.rs index 7d0f41e09..ff9db671e 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -172,6 +172,7 @@ fn main() { prost_build::Config::new() .boxed("Foo.bar") .boxed("Foo.oneof_field.box_qux") + .boxed("Foo.boxed_bar_list") .compile_protos(&[src.join("boxed_field.proto")], includes) .unwrap(); diff --git a/tests/src/boxed_field.proto b/tests/src/boxed_field.proto index 79b521e51..6876674c5 100644 --- a/tests/src/boxed_field.proto +++ b/tests/src/boxed_field.proto @@ -8,6 +8,7 @@ message Foo { string baz = 2; Bar box_qux = 3; } + repeated Bar boxed_bar_list = 4; } message Bar { diff --git a/tests/src/boxed_field.rs b/tests/src/boxed_field.rs index 88c1b5e93..9960fac69 100644 --- a/tests/src/boxed_field.rs +++ b/tests/src/boxed_field.rs @@ -3,15 +3,18 @@ include!(concat!(env!("OUT_DIR"), "/boxed_field.rs")); use self::foo::OneofField; #[test] -/// Confirm `Foo::bar` and `OneofField::BoxQux` is boxed by creating an instance +/// - Confirm `Foo::bar` and `OneofField::BoxQux` is boxed by creating an instance +/// - `Foo::boxed_bar_list` should not be boxed as it is a `Vec`, therefore it is already heap allocated fn test_boxed_field() { use alloc::boxed::Box; - let _ = Foo { + use alloc::vec::Vec; + let foo = Foo { bar: Some(Box::new(Bar {})), oneof_field: Some(OneofField::BoxQux(Box::new(Bar {}))), + boxed_bar_list: Vec::from([Bar {}]), }; let _ = Foo { - bar: Some(Box::new(Bar {})), oneof_field: Some(OneofField::Baz("hello".into())), + ..foo }; }