diff options
author | Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> | 2022-11-04 15:22:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-04 15:22:49 -0500 |
commit | e8ffb42ab66405ac56d04494a30e54b584f2d4dd (patch) | |
tree | 35076ed9ef6b63542a62c2ea3ecf7aac0b314d30 /bindgen/codegen/mod.rs | |
parent | bae6170907dd27a1e854236e2cc7b4f637220977 (diff) |
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.
Diffstat (limited to 'bindgen/codegen/mod.rs')
-rw-r--r-- | bindgen/codegen/mod.rs | 24 |
1 files changed, 18 insertions, 6 deletions
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 <Self as std::ops::Deref>::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) + } } } }; |