From e8ffb42ab66405ac56d04494a30e54b584f2d4dd Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:22:49 -0500 Subject: Wrap `unsafe` function's bodies in `unsafe` blocks (#2266) This guarantees that bindings generated by `bindgen` compile even if the `unsafe_op_in_unsafe_fn` lint is denied. --- bindgen/codegen/mod.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'bindgen/codegen/mod.rs') diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index d0c19136..e0d96cd1 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2605,7 +2605,9 @@ impl MethodCodegen for Method { methods.push(quote! { #(#attrs)* pub unsafe fn #name ( #( #args ),* ) #ret { - #block + unsafe { + #block + } } }); } @@ -4263,7 +4265,9 @@ fn objc_method_codegen( methods.push(quote! { unsafe fn #method_name #sig where ::Target: objc::Message + Sized { - #body + unsafe { + #body + } } }); } @@ -4638,12 +4642,16 @@ pub mod utils { #[inline] pub unsafe fn as_ref(&self) -> &T { - ::#prefix::mem::transmute(self) + unsafe { + ::#prefix::mem::transmute(self) + } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::#prefix::mem::transmute(self) + unsafe { + ::#prefix::mem::transmute(self) + } } } }; @@ -4757,12 +4765,16 @@ pub mod utils { #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::#prefix::slice::from_raw_parts(self.as_ptr(), len) + unsafe { + ::#prefix::slice::from_raw_parts(self.as_ptr(), len) + } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { + ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } } } }; -- cgit v1.2.3