From 795ed2d3395dff9ea4a540b6dac8dcf7a9bba1b8 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 13 Sep 2021 15:45:00 +0200 Subject: [PATCH] fix(core/rust): fix "unnecessary unsafe" warning [no changelog] --- core/embed/rust/src/protobuf/encode.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/embed/rust/src/protobuf/encode.rs b/core/embed/rust/src/protobuf/encode.rs index 78883e714..3f0b33cd2 100644 --- a/core/embed/rust/src/protobuf/encode.rs +++ b/core/embed/rust/src/protobuf/encode.rs @@ -38,12 +38,10 @@ pub extern "C" fn protobuf_encode(buf: Obj, obj: Obj) -> Obj { util::try_or_raise(|| { let obj = Gc::::try_from(obj)?; + // We assume there are no other refs into `buf` at this point. This specifically + // means that no fields of `obj` should reference `buf` memory. let buf = &mut BufferMut::try_from(buf)?; - let stream = &mut BufferStream::new(unsafe { - // SAFETY: We assume there are no other refs into `buf` at this point. This - // specifically means that no fields of `obj` should reference `buf` memory. - buf.as_mut() - }); + let stream = &mut BufferStream::new(buf.as_mut()); Encoder.encode_message(stream, &obj.def(), &obj)?;