Add missing #![deny(unsafe_op_in_unsafe_fn)] to upb/rust/lib.rs and fix violating functions
PiperOrigin-RevId: 655226304
diff --git a/rust/upb/lib.rs b/rust/upb/lib.rs
index bbfc106..650baec 100644
--- a/rust/upb/lib.rs
+++ b/rust/upb/lib.rs
@@ -4,8 +4,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
+#![deny(unsafe_op_in_unsafe_fn)]
mod arena;
+
pub use arena::{upb_Arena, Arena, RawArena};
mod array;
diff --git a/rust/upb/wire.rs b/rust/upb/wire.rs
index fe45558..75e666f 100644
--- a/rust/upb/wire.rs
+++ b/rust/upb/wire.rs
@@ -56,12 +56,12 @@
// SAFETY:
// - `mini_table` is the one associated with `msg`.
// - `buf` and `buf_size` are legally writable.
- let status = upb_Encode(msg, mini_table, 0, arena.raw(), &mut buf, &mut len);
+ let status = unsafe { upb_Encode(msg, mini_table, 0, arena.raw(), &mut buf, &mut len) };
if status == EncodeStatus::Ok {
assert!(!buf.is_null()); // EncodeStatus Ok should never return NULL data, even for len=0.
// SAFETY: upb guarantees that `buf` is valid to read for `len`.
- Ok((*std::ptr::slice_from_raw_parts(buf, len)).to_vec())
+ Ok(unsafe { &*std::ptr::slice_from_raw_parts(buf, len) }.to_vec())
} else {
Err(status)
}
@@ -87,7 +87,8 @@
// - `mini_table` is the one associated with `msg`
// - `buf` is legally readable for at least `buf_size` bytes.
// - `extreg` is null.
- let status = upb_Decode(buf, len, msg, mini_table, std::ptr::null(), options, arena.raw());
+ let status =
+ unsafe { upb_Decode(buf, len, msg, mini_table, std::ptr::null(), options, arena.raw()) };
match status {
DecodeStatus::Ok => Ok(()),
_ => Err(status),