diff options
107 files changed, 1009 insertions, 474 deletions
diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index f292d001..bc8477d5 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -89,8 +89,6 @@ jobs: - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test - env: - RUSTFLAGS: "-D unsafe_op_in_unsafe_fn -D unused_unsafe" test: runs-on: ${{matrix.os}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c9889f2..0664a6d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,8 @@ ## Added ## Changed + * Only wrap unsafe operations in unsafe blocks if the `--wrap_unsafe_ops` + option is enabled. * Replace the `name: &str` argument for `ParseCallbacks::add_derives` by `info: DeriveInfo`. diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 426e5cf7..f7fccc4f 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -562,6 +562,9 @@ where .value_name("override") .multiple_occurrences(true) .number_of_values(1), + Arg::new("wrap-unsafe-ops") + .long("wrap-unsafe-ops") + .help("Wrap unsafe operations in unsafe blocks."), Arg::new("V") .long("version") .help("Prints the version, and exits"), @@ -1085,5 +1088,9 @@ where } } + if matches.is_present("wrap-unsafe-ops") { + builder = builder.wrap_unsafe_ops(true); + } + Ok((builder, output, verbose)) } diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index ac6beee1..369e2c75 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index db35c226..3b72fb75 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -41,7 +41,7 @@ extern "C" { impl someClass { #[inline] pub unsafe fn somePublicMethod(&mut self, foo: ::std::os::raw::c_int) { - unsafe { someClass_somePublicMethod(self, foo) } + someClass_somePublicMethod(self, foo) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index 782ebdb4..cbc5ac9b 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index ea6456bd..63273e60 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs index f60d564a..12d5eab0 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -38,7 +38,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self, arg1) } + Foo_foo(self, arg1) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs index 317d5229..d860acd1 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs @@ -36,7 +36,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self, arg1) } + Foo_foo(self, arg1) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index 317d5229..d860acd1 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -36,7 +36,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self, arg1) } + Foo_foo(self, arg1) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs index e143e415..8a091cb5 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -16,11 +16,11 @@ pub mod root { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 91efa9b9..e9c1a76d 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -151,14 +151,14 @@ impl Foo { } #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char { - unsafe { Foo_type(self) } + Foo_type(self) } #[inline] pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type_(self, c) } + Foo_set_type_(self, c) } #[inline] pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type(self, c) } + Foo_set_type(self, c) } } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index 5b625f0a..eadc0694 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -30,6 +30,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn foo(&mut self) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self) } + Foo_foo(self) } } diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 9b2158fe..8542135b 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { @@ -490,18 +490,18 @@ extern "C" { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index 5163bae9..f6c3021e 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { @@ -44,11 +44,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { @@ -541,18 +541,18 @@ impl Clone for RealAbstractionWithTonsOfMethods { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index cf2122c6..42656079 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 033b0c3c..65e86b27 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -93,19 +93,19 @@ impl Default for C { impl C { #[inline] pub unsafe fn method(&mut self, c: C_MyInt) { - unsafe { C_method(self, c) } + C_method(self, c) } #[inline] pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) { - unsafe { C_methodRef(self, c) } + C_methodRef(self, c) } #[inline] pub unsafe fn complexMethodRef(&mut self, c: *mut C_Lookup) { - unsafe { C_complexMethodRef(self, c) } + C_complexMethodRef(self, c) } #[inline] pub unsafe fn anotherMethod(&mut self, c: AnotherInt) { - unsafe { C_anotherMethod(self, c) } + C_anotherMethod(self, c) } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 35c096d7..4b339dc3 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -35,10 +35,8 @@ extern "C" { impl Bar { #[inline] pub unsafe fn new() -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Bar_Bar(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Bar_Bar(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 615af667..2f13effb 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -37,19 +37,15 @@ extern "C" { impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } #[inline] pub unsafe fn new1(arg1: f64) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } } #[repr(C)] @@ -77,10 +73,8 @@ extern "C" { impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index c9818cca..b5d33332 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -39,19 +39,15 @@ extern "C" { impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload(&mut __bindgen_tmp, arg1); - __bindgen_tmp - } + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestOverload_TestOverload(&mut __bindgen_tmp, arg1); + __bindgen_tmp } #[inline] pub unsafe fn new1(arg1: f64) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); - __bindgen_tmp - } + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); + __bindgen_tmp } } #[repr(C)] @@ -79,10 +75,8 @@ extern "C" { impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); - __bindgen_tmp - } + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); + __bindgen_tmp } } diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 69a69618..96967bb4 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -34,11 +34,11 @@ extern "C" { impl A { #[inline] pub unsafe fn inline_definition(&mut self) { - unsafe { A_inline_definition(self) } + A_inline_definition(self) } #[inline] pub unsafe fn out_of_line_definition(&mut self) { - unsafe { A_out_of_line_definition(self) } + A_out_of_line_definition(self) } } #[repr(C)] @@ -84,10 +84,8 @@ extern "C" { impl C { #[inline] pub unsafe fn new(arg1: *mut C) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - C_C(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + C_C(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs index 97a539d9..ea6621dd 100644 --- a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -202,14 +202,14 @@ impl Foo { } #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char { - unsafe { Foo_type(self) } + Foo_type(self) } #[inline] pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type_(self, c) } + Foo_set_type_(self, c) } #[inline] pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type(self, c) } + Foo_set_type(self, c) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 067aab36..06c8da1b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index 604aa28d..a53b9ba8 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 78cbe47f..515f496b 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 8fdffe56..829022a2 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -50,7 +50,7 @@ impl BitStream { inputByteArray: *const ::std::os::raw::c_char, numberOfBytes: ::std::os::raw::c_uint, ) { - unsafe { BitStream_Write(self, inputByteArray, numberOfBytes) } + BitStream_Write(self, inputByteArray, numberOfBytes) } #[inline] pub unsafe fn Write1( @@ -58,10 +58,10 @@ impl BitStream { bitStream: *mut BitStream, numberOfBits: ::std::os::raw::c_uint, ) { - unsafe { BitStream_Write1(self, bitStream, numberOfBits) } + BitStream_Write1(self, bitStream, numberOfBits) } #[inline] pub unsafe fn Write11(&mut self) { - unsafe { BitStream_Write11(self) } + BitStream_Write11(self) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index 5ad4b23f..c834752e 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -20,7 +20,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -29,8 +29,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym)?; - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym)?; + let foo = __library.get(b"foo\0").map(|sym| *sym)?; + let baz = __library.get(b"baz\0").map(|sym| *sym)?; Ok(TestLib { __library, foo, @@ -48,9 +48,9 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { (self.foo)(x, y) } + (self.foo)(x, y) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - unsafe { (self.baz)() } + (self.baz)() } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs index 723f44ad..e46ffd49 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs @@ -23,7 +23,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -32,9 +32,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym)?; - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym)?; - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym)?; + let foo = __library.get(b"foo\0").map(|sym| *sym)?; + let bar = __library.get(b"bar\0").map(|sym| *sym)?; + let baz = __library.get(b"baz\0").map(|sym| *sym)?; Ok(TestLib { __library, foo, @@ -47,15 +47,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { (self.foo)(x, y) } + (self.foo)(x, y) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { (self.bar)(x) } + (self.bar)(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - unsafe { (self.baz)() } + (self.baz)() } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs index 5864ba0a..cae5bd69 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs @@ -32,7 +32,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -41,9 +41,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); + let baz = __library.get(b"baz\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -56,19 +56,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x, y) - } + (self.foo.as_ref().expect("Expected function, got error."))(x, y) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.bar.as_ref().expect("Expected function, got error."))(x) - } + (self.bar.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } + (self.baz.as_ref().expect("Expected function, got error."))() } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 6c9ea274..06e67ed7 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -20,7 +20,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -29,8 +29,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let foo1 = unsafe { __library.get(b"foo1\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let foo1 = __library.get(b"foo1\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -41,13 +41,9 @@ impl TestLib { &self, x: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn foo1(&self, x: f32) -> f32 { - unsafe { - (self.foo1.as_ref().expect("Expected function, got error."))(x) - } + (self.foo1.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index c9b24714..97bb67ab 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -34,7 +34,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -43,9 +43,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); - let bazz = unsafe { __library.get(b"bazz\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let baz = __library.get(b"baz\0").map(|sym| *sym); + let bazz = __library.get(b"bazz\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -57,16 +57,12 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.baz.as_ref().expect("Expected function, got error."))(x) - } + (self.baz.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 30f2be1d..af482ad9 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -46,19 +46,17 @@ extern "C" { impl X { #[inline] pub unsafe fn some_function(&mut self) { - unsafe { X_some_function(self) } + X_some_function(self) } #[inline] pub unsafe fn some_other_function(&mut self) { - unsafe { X_some_other_function(self) } + X_some_other_function(self) } #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - X_X(__bindgen_tmp.as_mut_ptr(), x); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + X_X(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } extern crate libloading; @@ -83,7 +81,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -92,8 +90,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -104,16 +102,12 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.bar.as_ref().expect("Expected function, got error."))(x) - } + (self.bar.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index d9287518..514cff73 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -46,19 +46,17 @@ extern "C" { impl A { #[inline] pub unsafe fn some_function(&mut self) { - unsafe { A_some_function(self) } + A_some_function(self) } #[inline] pub unsafe fn some_other_function(&mut self) { - unsafe { A_some_other_function(self) } + A_some_other_function(self) } #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - A_A(__bindgen_tmp.as_mut_ptr(), x); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } extern crate libloading; @@ -78,7 +76,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library<L>( library: L, @@ -87,8 +85,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -99,11 +97,9 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar(&self) -> () { - unsafe { (self.bar.as_ref().expect("Expected function, got error."))() } + (self.bar.as_ref().expect("Expected function, got error."))() } } diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index 59af8ef3..89b86379 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -30,10 +30,8 @@ extern "C" { impl Foo { #[inline] pub unsafe fn new(a: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), a); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), a); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 41095209..1711f76d 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -38,6 +38,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn destruct(&mut self) { - unsafe { Foo_Foo_destructor(self) } + Foo_Foo_destructor(self) } } diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 9ac66b0f..3cb865a4 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -30,7 +30,7 @@ extern "C" { impl Foo { #[inline] pub unsafe fn bar() -> ::std::os::raw::c_int { - unsafe { Foo_bar() } + Foo_bar() } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index d1ae7ebd..18061ea1 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -109,11 +109,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 89f1ac62..294e9f0e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -38,7 +38,7 @@ extern "C" { impl A { #[inline] pub unsafe fn make() -> A { - unsafe { make() } + make() } } #[repr(C)] @@ -74,6 +74,6 @@ extern "C" { impl B { #[inline] pub unsafe fn make() -> B { - unsafe { make1() } + make1() } } diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index 739ddf29..ad7463c2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -37,7 +37,7 @@ pub mod root { impl Value { #[inline] pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) { - unsafe { Value_a(self, arg1) } + Value_a(self, arg1) } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 0a6dd5e6..949db73b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -65,14 +65,12 @@ pub mod root { pub unsafe fn new( arg1: root::mozilla::detail::GuardObjectNotifier, ) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - JSAutoCompartment_JSAutoCompartment( - __bindgen_tmp.as_mut_ptr(), - arg1, - ); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + JSAutoCompartment_JSAutoCompartment( + __bindgen_tmp.as_mut_ptr(), + arg1, + ); + __bindgen_tmp.assume_init() } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index 019982db..61c7f792 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index 12a1e7a2..1a0131c3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 03162c4c..b69aa16e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index dc0b7f08..f8869528 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -89,15 +89,13 @@ extern "C" { impl Opaque { #[inline] pub unsafe fn eleven_out_of_ten(&mut self) -> SuchWow { - unsafe { Opaque_eleven_out_of_ten(self) } + Opaque_eleven_out_of_ten(self) } #[inline] pub unsafe fn new(pup: Pupper) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup); + __bindgen_tmp.assume_init() } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 32af443f..b4394993 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -100,11 +100,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 718a8024..466e7686 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -109,11 +109,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index de814146..d7fa0a63 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -100,11 +100,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs index f0b312a0..075ef46a 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 3788d3d0..90f7ed09 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -100,11 +100,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs index 85ca1601..53caa661 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs @@ -30,7 +30,7 @@ pub trait IFoo<ObjectType: 'static>: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, get) } + msg_send!(*self, get) } } #[repr(transparent)] @@ -59,6 +59,6 @@ pub trait IFooMultiGeneric<KeyType: 'static, ObjectType: 'static>: where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, objectForKey: key) } + msg_send!(*self, objectForKey: key) } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs index 7d732bb0..0d64a9ff 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { @@ -674,18 +674,18 @@ extern "C" { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs index 4364c69a..e8c2e077 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { @@ -44,11 +44,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { @@ -725,18 +725,18 @@ impl Clone for RealAbstractionWithTonsOfMethods { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 17154e4d..2af22cc4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 441c3f69..1de963bf 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -109,11 +109,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 4161c6db..ab402cfb 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs index df940912..f6a32704 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs @@ -109,11 +109,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { @@ -151,56 +151,56 @@ fn bindgen_test_layout_rte_kni_fifo() { concat!("Alignment of ", stringify!(rte_kni_fifo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(write) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(read) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(buffer) - ) + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) ); } impl Default for rte_kni_fifo { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs index 90d9d993..3c615035 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs @@ -30,7 +30,7 @@ pub trait IFoo<ObjectType: 'static>: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, get) } + msg_send!(*self, get) } } #[repr(transparent)] @@ -59,6 +59,6 @@ pub trait IFooMultiGeneric<KeyType: 'static, ObjectType: 'static>: where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, objectForKey: key) } + msg_send!(*self, objectForKey: key) } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs index 71a2d6d6..3066fac4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index 5f8a8474..e4627ac8 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -30,6 +30,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int { - unsafe { Foo_type(self) } + Foo_type(self) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs index 76971a5f..370cab93 100644 --- a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs @@ -14,13 +14,13 @@ pub trait PSomeProtocol: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, protocolMethod) } + msg_send!(*self, protocolMethod) } unsafe fn protocolClassMethod() where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(SomeProtocol), protocolClassMethod) } + msg_send!(class!(SomeProtocol), protocolClassMethod) } } #[repr(transparent)] @@ -45,13 +45,13 @@ pub trait IAllowlistMe: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } unsafe fn classMethod() where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(AllowlistMe), classMethod) } + msg_send!(class!(AllowlistMe), classMethod) } } impl AllowlistMe_InterestingCategory for AllowlistMe {} diff --git a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs index f16eb0f9..7d5d19b0 100644 --- a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs @@ -31,12 +31,12 @@ pub trait ISomeClass: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, ambiguouslyBlockedMethod) } + msg_send!(*self, ambiguouslyBlockedMethod) } unsafe fn instanceMethod(&self) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, instanceMethod) } + msg_send!(*self, instanceMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_category.rs b/bindgen-tests/tests/expectations/tests/objc_category.rs index f05c2bbd..9d60233b 100644 --- a/bindgen-tests/tests/expectations/tests/objc_category.rs +++ b/bindgen-tests/tests/expectations/tests/objc_category.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } } impl Foo_BarCategory for Foo {} @@ -39,6 +39,6 @@ pub trait Foo_BarCategory: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, categoryMethod) } + msg_send!(*self, categoryMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs index 0fe8e254..b322bddc 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class.rs @@ -33,6 +33,6 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class_method.rs b/bindgen-tests/tests/expectations/tests/objc_class_method.rs index 796698d2..29e70256 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class_method.rs @@ -30,31 +30,31 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), method) } + msg_send!(class!(Foo), method) } unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodWithInt: foo) } + msg_send!(class!(Foo), methodWithInt: foo) } unsafe fn methodWithFoo_(foo: Foo) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodWithFoo: foo) } + msg_send!(class!(Foo), methodWithFoo: foo) } unsafe fn methodReturningInt() -> ::std::os::raw::c_int where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodReturningInt) } + msg_send!(class!(Foo), methodReturningInt) } unsafe fn methodReturningFoo() -> Foo where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodReturningFoo) } + msg_send!(class!(Foo), methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( intvalue: ::std::os::raw::c_int, @@ -63,8 +63,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { - msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) - } + msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_method.rs b/bindgen-tests/tests/expectations/tests/objc_method.rs index 8962413e..593fd277 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method.rs @@ -30,31 +30,31 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } unsafe fn methodWithInt_(&self, foo: ::std::os::raw::c_int) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodWithInt: foo) } + msg_send!(*self, methodWithInt: foo) } unsafe fn methodWithFoo_(&self, foo: Foo) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodWithFoo: foo) } + msg_send!(*self, methodWithFoo: foo) } unsafe fn methodReturningInt(&self) -> ::std::os::raw::c_int where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodReturningInt) } + msg_send!(*self, methodReturningInt) } unsafe fn methodReturningFoo(&self) -> Foo where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodReturningFoo) } + msg_send!(*self, methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( &self, @@ -64,9 +64,7 @@ pub trait IFoo: Sized + std::ops::Deref { ) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { - msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) - } + msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( &self, @@ -78,9 +76,7 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { - msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) - } + msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) } } pub type instancetype = id; diff --git a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs index bd2df7d0..ac77cc19 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs @@ -30,12 +30,12 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, foo) } + msg_send!(*self, foo) } unsafe fn class_foo() where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), foo) } + msg_send!(class!(Foo), foo) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs index d49f17c1..1ec8494d 100644 --- a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs +++ b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs @@ -47,12 +47,12 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodUsingBar: my_bar) } + msg_send!(*self, methodUsingBar: my_bar) } unsafe fn methodReturningBar() -> Bar where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodReturningBar) } + msg_send!(class!(Foo), methodReturningBar) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs index 90a3dc8d..9f3fabd2 100644 --- a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs +++ b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs @@ -38,7 +38,7 @@ pub trait IFoo: Sized + std::ops::Deref { where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, func) } + msg_send!(*self, func) } unsafe fn setFunc_( &self, @@ -52,6 +52,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where <Self as std::ops::Deref>::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, setFunc: func) } + msg_send!(*self, setFunc: func) } } diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 4738b301..9f7dd20a 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -30,7 +30,7 @@ extern "C" { impl Struct { #[inline] pub unsafe fn Function(&mut self, arg1: *mut Union) { - unsafe { Struct_Function(self, arg1) } + Struct_Function(self, arg1) } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index 1d095b8d..979dd4b5 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -1,53 +1,53 @@ -#![allow(
- dead_code,
- non_snake_case,
- non_camel_case_types,
- non_upper_case_globals
-)]
-
-#[repr(C)]
-#[derive(Debug, Default)]
-pub struct cv_Foo {
- pub _address: u8,
-}
-#[test]
-fn bindgen_test_layout_cv_Foo() {
- assert_eq!(
- ::std::mem::size_of::<cv_Foo>(),
- 1usize,
- concat!("Size of: ", stringify!(cv_Foo))
- );
- assert_eq!(
- ::std::mem::align_of::<cv_Foo>(),
- 1usize,
- concat!("Alignment of ", stringify!(cv_Foo))
- );
-}
-extern "C" {
- #[link_name = "\u{1}_ZN2cv3FooD1Ev"]
- pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo);
-}
-impl cv_Foo {
- #[inline]
- pub unsafe fn destruct(&mut self) {
- unsafe { cv_Foo_Foo_destructor(self) }
- }
-}
-#[repr(C)]
-#[derive(Debug, Default)]
-pub struct cv_Bar {
- pub _address: u8,
-}
-#[test]
-fn bindgen_test_layout_cv_Bar() {
- assert_eq!(
- ::std::mem::size_of::<cv_Bar>(),
- 1usize,
- concat!("Size of: ", stringify!(cv_Bar))
- );
- assert_eq!(
- ::std::mem::align_of::<cv_Bar>(),
- 1usize,
- concat!("Alignment of ", stringify!(cv_Bar))
- );
-}
+#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default)] +pub struct cv_Foo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_cv_Foo() { + assert_eq!( + ::std::mem::size_of::<cv_Foo>(), + 1usize, + concat!("Size of: ", stringify!(cv_Foo)) + ); + assert_eq!( + ::std::mem::align_of::<cv_Foo>(), + 1usize, + concat!("Alignment of ", stringify!(cv_Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN2cv3FooD1Ev"] + pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); +} +impl cv_Foo { + #[inline] + pub unsafe fn destruct(&mut self) { + cv_Foo_Foo_destructor(self) + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct cv_Bar { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_cv_Bar() { + assert_eq!( + ::std::mem::size_of::<cv_Bar>(), + 1usize, + concat!("Size of: ", stringify!(cv_Bar)) + ); + assert_eq!( + ::std::mem::align_of::<cv_Bar>(), + 1usize, + concat!("Alignment of ", stringify!(cv_Bar)) + ); +} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index fd4d561b..8db33d11 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 52c6904c..55432d47 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index a777adf3..af795b64 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index eec37a3d..84a94603 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index 3376bf04..8e4143c0 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index 63e39781..a057cc34 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -16,11 +16,11 @@ pub mod root { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index f15ce0f0..22277468 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -100,11 +100,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index cb363de6..085e5ca3 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -62,6 +62,6 @@ impl Default for UnionWithDtor { impl UnionWithDtor { #[inline] pub unsafe fn destruct(&mut self) { - unsafe { UnionWithDtor_UnionWithDtor_destructor(self) } + UnionWithDtor_UnionWithDtor_destructor(self) } } diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 519bd869..67455aa8 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { @@ -98,6 +98,6 @@ extern "C" { impl UnionWithDtor { #[inline] pub unsafe fn destruct(&mut self) { - unsafe { UnionWithDtor_UnionWithDtor_destructor(self) } + UnionWithDtor_UnionWithDtor_destructor(self) } } diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index 621a961f..b5f94bcd 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs index 543f154d..487579f7 100644 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 316f8453..8b11e757 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index c06f6489..6ce6ed22 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -100,11 +100,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index 6c856634..f3e4b840 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index d4c6fec9..1562a8c9 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 96f03680..197a6bbf 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 869720d4..63b43baa 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index 4b1ab553..a1e452fe 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 227afaff..3c500b21 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -14,11 +14,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl<T> ::std::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 0310211d..8c6d0fd2 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -16,11 +16,11 @@ impl<T> __BindgenUnionField<T> { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::core::mem::transmute(self) } + ::core::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::core::mem::transmute(self) } + ::core::mem::transmute(self) } } impl<T> ::core::default::Default for __BindgenUnionField<T> { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 22e7e6ed..37fdd951 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -43,11 +43,9 @@ extern "C" { impl Bar { #[inline] pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz); + __bindgen_tmp.assume_init() } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 909d04de..6d15c51f 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -33,10 +33,8 @@ extern "C" { impl Foo { #[inline] pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index f144edd4..92bb13cc 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -39,13 +39,13 @@ extern "thiscall" { impl Foo { #[inline] pub unsafe fn test(&mut self) { - unsafe { Foo_test(self) } + Foo_test(self) } #[inline] pub unsafe fn test2( &mut self, var: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_test2(self, var) } + Foo_test2(self, var) } } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs new file mode 100644 index 00000000..0eef6d2e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs @@ -0,0 +1,107 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } + } +} +impl<T> ::std::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::std::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::std::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::std::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::std::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult { + pub mResult: ::std::os::raw::c_int, + pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, + pub mMightHaveUnreported: bool, + pub mUnionState: TErrorResult_UnionState, +} +pub const TErrorResult_UnionState_HasMessage: TErrorResult_UnionState = 0; +pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = 0; +pub type TErrorResult_UnionState = i32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult_Message { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult_DOMExceptionInfo { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct TErrorResult__bindgen_ty_1 { + pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, + pub mDOMExceptionInfo: + __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, + pub bindgen_union_field: u64, +} +impl Default for TErrorResult { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct ErrorResult { + pub _base: TErrorResult, +} +impl Clone for ErrorResult { + fn clone(&self) -> Self { + *self + } +} +impl Default for ErrorResult { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs new file mode 100644 index 00000000..d621b450 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs @@ -0,0 +1,215 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct C { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], +} +impl Default for C { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug)] +pub struct C_with_zero_length_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +impl Default for C_with_zero_length_array { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[repr(C)] +#[derive(Debug)] +pub struct C_with_incomplete_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +impl Default for C_with_incomplete_array { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[repr(C)] +#[derive(Debug)] +pub struct C_with_zero_length_array_and_incomplete_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +impl Default for C_with_zero_length_array_and_incomplete_array { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_and_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct WithDtor { + pub b: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug)] +pub struct IncompleteArrayNonCopiable { + pub whatever: *mut ::std::os::raw::c_void, + pub incomplete_array: __IncompleteArrayField<C>, +} +impl Default for IncompleteArrayNonCopiable { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union Union { + pub d: f32, + pub i: ::std::os::raw::c_int, +} +impl Default for Union { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct WithUnion { + pub data: Union, +} +impl Default for WithUnion { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct RealAbstractionWithTonsOfMethods { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar( + this: *const RealAbstractionWithTonsOfMethods, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar1( + this: *mut RealAbstractionWithTonsOfMethods, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] + pub fn RealAbstractionWithTonsOfMethods_bar2( + this: *mut RealAbstractionWithTonsOfMethods, + foo: ::std::os::raw::c_int, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] + pub fn RealAbstractionWithTonsOfMethods_sta(); +} +impl RealAbstractionWithTonsOfMethods { + #[inline] + pub unsafe fn bar(&self) { + unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + } + #[inline] + pub unsafe fn bar1(&mut self) { + unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + } + #[inline] + pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { + unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + } + #[inline] + pub unsafe fn sta() { + unsafe { RealAbstractionWithTonsOfMethods_sta() } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs new file mode 100644 index 00000000..5864ba0a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -0,0 +1,74 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + pub foo: Result< + unsafe extern "C" fn( + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + pub bar: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + pub baz: Result< + unsafe extern "C" fn() -> ::std::os::raw::c_int, + ::libloading::Error, + >, +} +impl TestLib { + pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error> + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + unsafe { Self::from_library(library) } + } + pub unsafe fn from_library<L>( + library: L, + ) -> Result<Self, ::libloading::Error> + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); + Ok(TestLib { + __library, + foo, + bar, + baz, + }) + } + pub unsafe fn foo( + &self, + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int { + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x, y) + } + } + pub unsafe fn bar( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + unsafe { + (self.bar.as_ref().expect("Expected function, got error."))(x) + } + } + pub unsafe fn baz(&self) -> ::std::os::raw::c_int { + unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs new file mode 100644 index 00000000..0fe8e254 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs @@ -0,0 +1,38 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] + +use objc::{self, class, msg_send, sel, sel_impl}; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +extern "C" { + pub static mut fooVar: Foo; +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct Foo(pub id); +impl std::ops::Deref for Foo { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Foo {} +impl Foo { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(Foo), alloc) }) + } +} +impl IFoo for Foo {} +pub trait IFoo: Sized + std::ops::Deref { + unsafe fn method(&self) + where + <Self as std::ops::Deref>::Target: objc::Message + Sized, + { + unsafe { msg_send!(*self, method) } + } +} diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index e99abb87..d7d0f661 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index 27c48f0e..4ba52498 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -23,11 +23,11 @@ impl<T> __IncompleteArrayField<T> { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp new file mode 100644 index 00000000..3b595f2e --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp @@ -0,0 +1,22 @@ +// bindgen-flags: --rust-target 1.0 --wrap-unsafe-ops --no-layout-tests + +template<typename T> +struct TErrorResult { + enum UnionState { + HasMessage, + HasException, + }; + int mResult; + struct Message; + struct DOMExceptionInfo; + union { + Message* mMessage; + DOMExceptionInfo* mDOMExceptionInfo; + }; + + bool mMightHaveUnreported; + UnionState mUnionState; +}; + +struct ErrorResult : public TErrorResult<int> { +}; diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp b/bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp new file mode 100644 index 00000000..e3d11c57 --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp @@ -0,0 +1,74 @@ +// bindgen-flags: --wrap-unsafe-ops --no-layout-tests + +class C { + int a; + // More than rust limits (32) + char big_array[33]; +}; + +class C_with_zero_length_array { + int a; + // More than rust limits (32) + char big_array[33]; + char zero_length_array[0]; +}; + +class C_with_zero_length_array_2 { + int a; + char zero_length_array[0]; +}; + +class C_with_incomplete_array { + int a; + // More than rust limits (32) + char big_array[33]; + char incomplete_array[]; +}; + +class C_with_incomplete_array_2 { + int a; + char incomplete_array[]; +}; + +class C_with_zero_length_array_and_incomplete_array { + int a; + // More than rust limits (32) + char big_array[33]; + char zero_length_array[0]; + char incomplete_array[]; +}; + +class C_with_zero_length_array_and_incomplete_array_2 { + int a; + char zero_length_array[0]; + char incomplete_array[]; +}; + +class WithDtor { + int b; + + ~WithDtor() {} +}; + +class IncompleteArrayNonCopiable { + void* whatever; + C incomplete_array[]; +}; + +union Union { + float d; + int i; +}; + +class WithUnion { + Union data; +}; + +class RealAbstractionWithTonsOfMethods { + void foo(); +public: + void bar() const; + void bar(); + void bar(int foo); + static void sta(); +}; diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h b/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h new file mode 100644 index 00000000..2b8c1071 --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h @@ -0,0 +1,5 @@ +// bindgen-flags: --dynamic-loading TestLib --wrap-unsafe-ops + +int foo(int x, int y); +int bar(void *x); +int baz(); diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h b/bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h new file mode 100644 index 00000000..017795c8 --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h @@ -0,0 +1,10 @@ +// bindgen-flags: --wrap-unsafe-ops -- -x objective-c +// bindgen-osx-only + +@class Foo; + +Foo* fooVar; + +@interface Foo +-(void)method; +@end diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index f310f14e..5e734ccd 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -1,4 +1,5 @@ use crate::codegen; +use crate::ir::context::BindgenContext; use crate::ir::function::ClangAbi; use proc_macro2::Ident; @@ -72,12 +73,22 @@ impl DynamicItems { Self::default() } - pub fn get_tokens(&self, lib_ident: Ident) -> proc_macro2::TokenStream { + pub fn get_tokens( + &self, + lib_ident: Ident, + ctx: &BindgenContext, + ) -> proc_macro2::TokenStream { let struct_members = &self.struct_members; let constructor_inits = &self.constructor_inits; let init_fields = &self.init_fields; let struct_implementation = &self.struct_implementation; + let from_library = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { Self::from_library(library) }) + } else { + quote!(Self::from_library(library)) + }; + quote! { extern crate libloading; @@ -92,9 +103,7 @@ impl DynamicItems { ) -> Result<Self, ::libloading::Error> where P: AsRef<::std::ffi::OsStr> { let library = ::libloading::Library::new(path)?; - unsafe { - Self::from_library(library) - } + #from_library } pub unsafe fn from_library<L>( @@ -126,6 +135,7 @@ impl DynamicItems { ret: proc_macro2::TokenStream, ret_ty: proc_macro2::TokenStream, attributes: Vec<proc_macro2::TokenStream>, + ctx: &BindgenContext, ) { if !is_variadic { assert_eq!(args.len(), args_identifiers.len()); @@ -149,8 +159,10 @@ impl DynamicItems { } else { quote! { self.#ident.as_ref().expect("Expected function, got error.") } }; - let call_body = quote! { - (#fn_)(#( #args_identifiers ),*) + let call_body = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { (#fn_)(#( #args_identifiers ),*) }) + } else { + quote!((#fn_)(#( #args_identifiers ),*) ) }; // We can't implement variadic functions from C easily, so we allow to @@ -159,22 +171,26 @@ impl DynamicItems { self.struct_implementation.push(quote! { #(#attributes)* pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - unsafe { - #call_body - } + #call_body } }); } // N.B: Unwrap the signature upon construction if it is required to be resolved. let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); + let library_get = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { __library.get(#ident_str) }) + } else { + quote!(__library.get(#ident_str)) + }; + self.constructor_inits.push(if is_required { quote! { - let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym)?; + let #ident = #library_get.map(|sym| *sym)?; } } else { quote! { - let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym); + let #ident = #library_get.map(|sym| *sym); } }); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c1e92b77..e5372427 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2585,9 +2585,7 @@ impl MethodCodegen for Method { }) } - let block = quote! { - #( #stmts );* - }; + let block = ctx.wrap_unsafe_ops(quote! ( #( #stmts );*)); let mut attrs = vec![attributes::inline()]; @@ -2601,9 +2599,7 @@ impl MethodCodegen for Method { methods.push(quote! { #(#attrs)* pub unsafe fn #name ( #( #args ),* ) #ret { - unsafe { - #block - } + #block } }); } @@ -4169,6 +4165,7 @@ impl CodeGenerator for Function { ret, ret_ty, attributes, + ctx, ); } else { result.push(tokens); @@ -4212,17 +4209,18 @@ fn objc_method_codegen( let methods_and_args = method.format_method_call(&fn_args); - let body = if method.is_class_method() { - let class_name = ctx.rust_ident( - class_name.expect("Generating a class method without class name?"), - ); - quote! { - msg_send!(class!(#class_name), #methods_and_args) - } - } else { - quote! { - msg_send!(*self, #methods_and_args) - } + let body = { + let body = if method.is_class_method() { + let class_name = ctx.rust_ident( + class_name + .expect("Generating a class method without class name?"), + ); + quote!(msg_send!(class!(#class_name), #methods_and_args)) + } else { + quote!(msg_send!(*self, #methods_and_args)) + }; + + ctx.wrap_unsafe_ops(body) }; let method_name = @@ -4230,9 +4228,7 @@ fn objc_method_codegen( methods.push(quote! { unsafe fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized { - unsafe { - #body - } + #body } }); } @@ -4495,7 +4491,7 @@ pub(crate) fn codegen( if let Some(ref lib_name) = context.options().dynamic_library_name { let lib_ident = context.rust_ident(lib_name); let dynamic_items_tokens = - result.dynamic_items().get_tokens(lib_ident); + result.dynamic_items().get_tokens(lib_ident, context); result.push(dynamic_items_tokens); } @@ -4598,6 +4594,9 @@ pub mod utils { pub struct __BindgenUnionField<T>(::#prefix::marker::PhantomData<T>); }; + let transmute = + ctx.wrap_unsafe_ops(quote!(::#prefix::mem::transmute(self))); + let union_field_impl = quote! { impl<T> __BindgenUnionField<T> { #[inline] @@ -4607,16 +4606,12 @@ pub mod utils { #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { - ::#prefix::mem::transmute(self) - } + #transmute } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { - ::#prefix::mem::transmute(self) - } + #transmute } } }; @@ -4711,6 +4706,13 @@ pub mod utils { ::#prefix::marker::PhantomData<T>, [T; 0]); }; + let from_raw_parts = ctx.wrap_unsafe_ops(quote! ( + ::#prefix::slice::from_raw_parts(self.as_ptr(), len) + )); + let from_raw_parts_mut = ctx.wrap_unsafe_ops(quote! ( + ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + )); + let incomplete_array_impl = quote! { impl<T> __IncompleteArrayField<T> { #[inline] @@ -4730,16 +4732,12 @@ pub mod utils { #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { - ::#prefix::slice::from_raw_parts(self.as_ptr(), len) - } + #from_raw_parts } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { - ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } + #from_raw_parts_mut } } }; diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 928f2406..4623b253 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -25,7 +25,8 @@ use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; use cexpr; use clang_sys; -use proc_macro2::{Ident, Span}; +use proc_macro2::{Ident, Span, TokenStream}; +use quote::ToTokens; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; @@ -2702,6 +2703,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().must_use_types.matches(name) } + + pub(crate) fn wrap_unsafe_ops(&self, tokens: impl ToTokens) -> TokenStream { + if self.options.wrap_unsafe_ops { + quote!(unsafe { #tokens }) + } else { + tokens.into_token_stream() + } + } } /// A builder struct for configuring item resolution options. diff --git a/bindgen/lib.rs b/bindgen/lib.rs index d281e949..53bbd887 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -645,6 +645,10 @@ impl Builder { output_vector.push("--merge-extern-blocks".into()); } + if self.options.wrap_unsafe_ops { + output_vector.push("--wrap-unsafe-ops".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1770,6 +1774,12 @@ impl Builder { .insert(arg.into()); self } + + /// If true, wraps unsafe operations in unsafe blocks. + pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { + self.options.wrap_unsafe_ops = doit; + self + } } /// Configuration options for generated bindings. @@ -2107,6 +2117,9 @@ struct BindgenOptions { merge_extern_blocks: bool, abi_overrides: HashMap<Abi, RegexSet>, + + /// Whether to wrap unsafe operations in unsafe blocks or not. + wrap_unsafe_ops: bool, } impl BindgenOptions { @@ -2298,6 +2311,7 @@ impl Default for BindgenOptions { sort_semantically, merge_extern_blocks, abi_overrides, + wrap_unsafe_ops, } } } |