cleanup upb.rs

We shouldn't give easy access to the zeroed block, so let's pass in pbi::private to deter misuse.
Also saw that arena wasn't used mutably in a repeatedfield test, so let mut -> let;

PiperOrigin-RevId: 574896460
pull/14435/head
Hong Shin 2 years ago committed by Copybara-Service
parent 287374e5eb
commit 2690017b16
  1. 4
      rust/upb.rs
  2. 2
      src/google/protobuf/compiler/rust/accessors/singular_message.cc

@ -150,7 +150,7 @@ const UPB_SCRATCH_SPACE_BYTES: usize = 64_000;
/// with readonly access.
pub struct ScratchSpace;
impl ScratchSpace {
pub fn zeroed_block() -> RawMessage {
pub fn zeroed_block(_private: Private) -> RawMessage {
unsafe {
INIT.call_once(|| {
let layout =
@ -455,7 +455,7 @@ mod tests {
#[test]
fn i32_array() {
let mut arena = Arena::new();
let arena = Arena::new();
let mut arr = RepeatedField::<i32>::new(&arena);
assert_eq!(arr.len(), 0);
arr.push(1);

@ -51,7 +51,7 @@ void SingularMessage::InMsgImpl(Context<FieldDescriptor> field) const {
// a null ptr received from upb manifests as Option::None
match submsg {
// TODO:(b/304357029)
None => $prefix$View::new($pbi$::Private, $pbr$::ScratchSpace::zeroed_block()),
None => $prefix$View::new($pbi$::Private, $pbr$::ScratchSpace::zeroed_block($pbi$::Private)),
Some(field) => $prefix$View::new($pbi$::Private, field),
}
}

Loading…
Cancel
Save