diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d3494e75..74ff973751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -229,6 +229,7 @@ ## Added ## Changed ## Removed +- Removed support for generating code for rustc versions < 1.51. ## Fixed - Typo in code for `--rustified-non-exhaustive-enums` (#3266) ## Security 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 07eb7a80f6..ec152e1543 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -4,12 +4,12 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); - assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { #[must_use] #[link_name = "\u{1}_ZN3Foo3fooEi"] pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; @@ -21,7 +21,7 @@ impl Foo { Foo_foo(self, arg1) } } -extern "C" { +unsafe extern "C" { #[must_use] #[link_name = "\u{1}_Z3fooi"] pub fn foo(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; 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 aa01540b0e..f0fb434bcb 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 @@ -4,12 +4,12 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); - assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEi"] pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } @@ -19,7 +19,7 @@ impl Foo { Foo_foo(self, arg1) } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooi"] pub fn foo(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } 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 f3d7893b00..2c8d2e5713 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -12,29 +12,19 @@ pub mod root { pub foo: ::std::os::raw::c_int, pub bar: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of Bar"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Bar"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - "Offset of field: Bar::foo", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: Bar::bar", - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::foo"][::std::mem::offset_of!(Bar, foo) - 0usize]; + ["Offset of field: Bar::bar"][::std::mem::offset_of!(Bar, bar) - 0usize]; + }; impl Default for Bar { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 69591d1bce..98ee43b374 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -30,28 +30,18 @@ impl ::std::fmt::Debug for __IncompleteArrayField { } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct C { pub a: ::std::os::raw::c_int, pub big_array: [::std::os::raw::c_char; 33usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 40usize, "Size of C"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: C::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - "Offset of field: C::big_array", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 40usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::a"][::std::mem::offset_of!(C, a) - 0usize]; + ["Offset of field: C::big_array"][::std::mem::offset_of!(C, big_array) - 4usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -62,43 +52,30 @@ impl Default for C { } } #[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>, } -#[test] -fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of C_with_zero_length_array", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 40usize]; + [ "Alignment of C_with_zero_length_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: C_with_zero_length_array::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(C_with_zero_length_array, a) - 0usize]; + [ "Offset of field: C_with_zero_length_array::big_array", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, + ][::std::mem::offset_of!(C_with_zero_length_array, big_array) - 4usize]; + [ "Offset of field: C_with_zero_length_array::zero_length_array", - ); -} + ][::std::mem::offset_of!(C_with_zero_length_array, zero_length_array) - 37usize]; +}; impl Default for C_with_zero_length_array { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -114,69 +91,46 @@ 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>, } -#[test] -fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of C_with_zero_length_array_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 4usize]; + [ "Alignment of C_with_zero_length_array_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: C_with_zero_length_array_2::a", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, + ][::std::mem::offset_of!(C_with_zero_length_array_2, a) - 0usize]; + [ "Offset of field: C_with_zero_length_array_2::zero_length_array", - ); -} + ][::std::mem::offset_of!(C_with_zero_length_array_2, zero_length_array) - 4usize]; +}; #[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>, } -#[test] -fn bindgen_test_layout_C_with_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of C_with_incomplete_array", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 40usize]; + [ "Alignment of C_with_incomplete_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: C_with_incomplete_array::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(C_with_incomplete_array, a) - 0usize]; + [ "Offset of field: C_with_incomplete_array::big_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, + ][::std::mem::offset_of!(C_with_incomplete_array, big_array) - 4usize]; + [ "Offset of field: C_with_incomplete_array::incomplete_array", - ); -} + ][::std::mem::offset_of!(C_with_incomplete_array, incomplete_array) - 37usize]; +}; impl Default for C_with_incomplete_array { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -192,77 +146,55 @@ pub struct C_with_incomplete_array_2 { pub a: ::std::os::raw::c_int, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_C_with_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of C_with_incomplete_array_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 4usize]; + [ "Alignment of C_with_incomplete_array_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: C_with_incomplete_array_2::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(C_with_incomplete_array_2, a) - 0usize]; + [ "Offset of field: C_with_incomplete_array_2::incomplete_array", - ); -} + ][::std::mem::offset_of!(C_with_incomplete_array_2, incomplete_array) - 4usize]; +}; #[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>, } -#[test] -fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit< - C_with_zero_length_array_and_incomplete_array, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of C_with_zero_length_array_and_incomplete_array", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 40usize]; + [ "Alignment of C_with_zero_length_array_and_incomplete_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(C_with_zero_length_array_and_incomplete_array, a) - 0usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array::big_array", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, + ][::std::mem::offset_of!(C_with_zero_length_array_and_incomplete_array, big_array) + - 4usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array::zero_length_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, + ][::std::mem::offset_of!( + C_with_zero_length_array_and_incomplete_array, zero_length_array + ) - 37usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array::incomplete_array", - ); -} + ][::std::mem::offset_of!( + C_with_zero_length_array_and_incomplete_array, incomplete_array + ) - 37usize]; +}; impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -279,87 +211,62 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit< - C_with_zero_length_array_and_incomplete_array_2, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of C_with_zero_length_array_and_incomplete_array_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 4usize]; + [ "Alignment of C_with_zero_length_array_and_incomplete_array_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() + - 4usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array_2::a", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, + ][::std::mem::offset_of!(C_with_zero_length_array_and_incomplete_array_2, a) + - 0usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array_2::zero_length_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!( + C_with_zero_length_array_and_incomplete_array_2, zero_length_array + ) - 4usize]; + [ "Offset of field: C_with_zero_length_array_and_incomplete_array_2::incomplete_array", - ); -} + ][::std::mem::offset_of!( + C_with_zero_length_array_and_incomplete_array_2, incomplete_array + ) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct WithDtor { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of WithDtor"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of WithDtor"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: WithDtor::b", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithDtor"][::std::mem::size_of::() - 4usize]; + ["Alignment of WithDtor"][::std::mem::align_of::() - 4usize]; + ["Offset of field: WithDtor::b"][::std::mem::offset_of!(WithDtor, b) - 0usize]; +}; #[repr(C)] +#[derive(Debug)] pub struct IncompleteArrayNonCopiable { pub whatever: *mut ::std::os::raw::c_void, pub incomplete_array: __IncompleteArrayField, } -#[test] -fn bindgen_test_layout_IncompleteArrayNonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of IncompleteArrayNonCopiable", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 8usize]; + [ "Alignment of IncompleteArrayNonCopiable", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: IncompleteArrayNonCopiable::whatever", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(IncompleteArrayNonCopiable, whatever) - 0usize]; + [ "Offset of field: IncompleteArrayNonCopiable::incomplete_array", - ); -} + ][::std::mem::offset_of!(IncompleteArrayNonCopiable, incomplete_array) - 8usize]; +}; impl Default for IncompleteArrayNonCopiable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -375,23 +282,13 @@ pub union Union { pub d: f32, pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of Union"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Union"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - "Offset of field: Union::d", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - "Offset of field: Union::i", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Union"][::std::mem::size_of::() - 4usize]; + ["Alignment of Union"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Union::d"][::std::mem::offset_of!(Union, d) - 0usize]; + ["Offset of field: Union::i"][::std::mem::offset_of!(Union, i) - 0usize]; +}; impl Default for Union { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -406,18 +303,14 @@ impl Default for Union { pub struct WithUnion { pub data: Union, } -#[test] -fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of WithUnion"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of WithUnion"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithUnion"][::std::mem::size_of::() - 4usize]; + ["Alignment of WithUnion"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: WithUnion::data", - ); -} + ][::std::mem::offset_of!(WithUnion, data) - 0usize]; +}; impl Default for WithUnion { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -432,39 +325,35 @@ impl Default for WithUnion { pub struct RealAbstractionWithTonsOfMethods { pub _address: u8, } -#[test] -fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of RealAbstractionWithTonsOfMethods", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, + ][::std::mem::size_of::() - 1usize]; + [ "Alignment of RealAbstractionWithTonsOfMethods", - ); -} -extern "C" { + ][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] pub fn RealAbstractionWithTonsOfMethods_bar( this: *const RealAbstractionWithTonsOfMethods, ); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] pub fn RealAbstractionWithTonsOfMethods_bar1( this: *mut RealAbstractionWithTonsOfMethods, ); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] pub fn RealAbstractionWithTonsOfMethods_bar2( this: *mut RealAbstractionWithTonsOfMethods, foo: ::std::os::raw::c_int, ); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] pub fn RealAbstractionWithTonsOfMethods_sta(); } diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index 0563b4e65d..5dbda00007 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -4,16 +4,12 @@ pub struct TestOverload { pub _address: u8, } -#[test] -fn bindgen_test_layout_TestOverload() { - assert_eq!(::std::mem::size_of::(), 1usize, "Size of TestOverload"); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of TestOverload", - ); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestOverload"][::std::mem::size_of::() - 1usize]; + ["Alignment of TestOverload"][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { /// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that. #[link_name = "\u{1}_ZN12TestOverloadC1Ei"] pub fn TestOverload_TestOverload( @@ -21,7 +17,7 @@ extern "C" { arg1: ::std::os::raw::c_int, ); } -extern "C" { +unsafe extern "C" { /// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that. #[link_name = "\u{1}_ZN12TestOverloadC1Ed"] pub fn TestOverload_TestOverload1(this: *mut TestOverload, arg1: f64); @@ -29,15 +25,15 @@ extern "C" { impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload(&mut __bindgen_tmp, arg1); - __bindgen_tmp + 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 { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); - __bindgen_tmp + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } } #[repr(C)] @@ -45,28 +41,22 @@ impl TestOverload { pub struct TestPublicNoArgs { pub _address: u8, } -#[test] -fn bindgen_test_layout_TestPublicNoArgs() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - "Size of TestPublicNoArgs", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestPublicNoArgs"][::std::mem::size_of::() - 1usize]; + [ "Alignment of TestPublicNoArgs", - ); -} -extern "C" { + ][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"] pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs); } impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); - __bindgen_tmp + 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/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs index c2a9d33ca6..7fa8bc41ab 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 @@ -32,6 +32,16 @@ where Self::extract_bit(byte, index) } #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; + Self::extract_bit(byte, index) + } + #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -49,6 +59,16 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize) + }; + unsafe { *byte = Self::change_bit(*byte, index, val) }; + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -69,6 +89,26 @@ where val } #[inline] + pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -86,38 +126,50 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } + #[inline] + pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; + } + } } /** Because this struct have array larger than 32 items and --with-derive-partialeq --impl-partialeq --impl-debug is provided, this struct should manually implement `Debug` and `PartialEq`.*/ #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct Foo { pub large: [::std::os::raw::c_int; 33usize], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: u16, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 136usize, "Size of Foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - "Offset of field: Foo::large", - ); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 136usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::large"][::std::mem::offset_of!(Foo, large) - 0usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo9set_type_Ec"] pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo8set_typeEc"] pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char); } @@ -130,33 +182,6 @@ impl Default for Foo { } } } -impl ::std::fmt::Debug for Foo { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!( - f, - "Foo {{ large: [{}], type_ : {:?}, }}", - { - use std::fmt::Write as _; - let mut output = String::new(); - let mut iter = self.large.iter(); - if let Some(value) = iter.next() { - let _ = write!(output, "{value:?}"); - for value in iter { - let _ = write!(output, ", {value:?}"); - } - } - output - }, - self.type__bindgen_bitfield(), - ) - } -} -impl ::std::cmp::PartialEq for Foo { - fn eq(&self, other: &Foo) -> bool { - &self.large[..] == &other.large[..] - && self.type__bindgen_bitfield() == other.type__bindgen_bitfield() - } -} impl Foo { #[inline] pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { @@ -170,6 +195,35 @@ impl Foo { } } #[inline] + pub unsafe fn type__bindgen_bitfield_raw( + this: *const Self, + ) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 3u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_type__bindgen_bitfield_raw( + this: *mut Self, + val: ::std::os::raw::c_char, + ) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { diff --git a/bindgen-tests/tests/expectations/tests/derive-clone.rs b/bindgen-tests/tests/expectations/tests/derive-clone.rs index d903afa06f..ccbdf5bd70 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone.rs @@ -1,30 +1,20 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This struct should derive `Clone`. #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct ShouldDeriveClone { pub large: [::std::os::raw::c_int; 33usize], } -#[test] -fn bindgen_test_layout_ShouldDeriveClone() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - "Size of ShouldDeriveClone", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ShouldDeriveClone"][::std::mem::size_of::() - 132usize]; + [ "Alignment of ShouldDeriveClone", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: ShouldDeriveClone::large", - ); -} + ][::std::mem::offset_of!(ShouldDeriveClone, large) - 0usize]; +}; impl Default for ShouldDeriveClone { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs index c5eed87ae5..87cbb7346c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs @@ -151,18 +151,12 @@ pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 204usize, "Size of C"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 4usize, - "Offset of field: C::large_array", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 204usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::large_array"][::std::mem::offset_of!(C, large_array) - 4usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs index baeb87545d..937ad4ad0c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -33,6 +33,16 @@ where Self::extract_bit(byte, index) } #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; + Self::extract_bit(byte, index) + } + #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -50,6 +60,16 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize) + }; + unsafe { *byte = Self::change_bit(*byte, index, val) }; + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -70,6 +90,26 @@ where val } #[inline] + pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -87,25 +127,39 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } + #[inline] + pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; + } + } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - pub large_array: [::std::os::raw::c_int; 50usize], + pub large_array: [::core::ffi::c_int; 50usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::core::mem::size_of::(), 204usize, "Size of C"); - assert_eq!(::core::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::core::mem::size_of::() - 204usize]; + ["Alignment of C"][::core::mem::align_of::() - 4usize]; + [ "Offset of field: C::large_array", - ); -} + ][::core::mem::offset_of!(C, large_array) - 4usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); @@ -115,11 +169,6 @@ impl Default for C { } } } -impl ::core::fmt::Debug for C { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - write!(f, "C {{ a : {:?}, b : {:?}, large_array: [...] }}", self.a(), self.b()) - } -} impl C { #[inline] pub fn a(&self) -> bool { @@ -133,6 +182,31 @@ impl C { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> bool { + unsafe { + ::core::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::core::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::core::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::core::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> bool { unsafe { ::core::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } @@ -144,6 +218,31 @@ impl C { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> bool { + unsafe { + ::core::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::core::ptr::addr_of!((*this)._bitfield_1), 1usize, 7u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::core::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::core::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index e414b6fa32..87cbb7346c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -32,6 +32,16 @@ where Self::extract_bit(byte, index) } #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; + Self::extract_bit(byte, index) + } + #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -49,6 +59,16 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize) + }; + unsafe { *byte = Self::change_bit(*byte, index, val) }; + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -69,6 +89,26 @@ where val } #[inline] + pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -86,25 +126,37 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } + #[inline] + pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; + } + } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 204usize, "Size of C"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 4usize, - "Offset of field: C::large_array", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 204usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::large_array"][::std::mem::offset_of!(C, large_array) - 4usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -114,28 +166,6 @@ impl Default for C { } } } -impl ::std::fmt::Debug for C { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!( - f, - "C {{ a : {:?}, b : {:?}, large_array: [{}] }}", - self.a(), - self.b(), - { - use std::fmt::Write as _; - let mut output = String::new(); - let mut iter = self.large_array.iter(); - if let Some(value) = iter.next() { - let _ = write!(output, "{value:?}"); - for value in iter { - let _ = write!(output, ", {value:?}"); - } - } - output - }, - ) - } -} impl C { #[inline] pub fn a(&self) -> bool { @@ -149,6 +179,30 @@ impl C { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } @@ -160,6 +214,30 @@ impl C { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 7u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs index 9fe1f5518c..eaaa8ef9d4 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs @@ -1,6 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct Nice { pub pointer: Nice_Function, pub large_array: [::std::os::raw::c_int; 34usize], @@ -8,23 +8,15 @@ pub struct Nice { pub type Nice_Function = ::std::option::Option< unsafe extern "C" fn(data: ::std::os::raw::c_int), >; -#[test] -fn bindgen_test_layout_Nice() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 144usize, "Size of Nice"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Nice"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, - 0usize, - "Offset of field: Nice::pointer", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 8usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Nice"][::std::mem::size_of::() - 144usize]; + ["Alignment of Nice"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Nice::pointer"][::std::mem::offset_of!(Nice, pointer) - 0usize]; + [ "Offset of field: Nice::large_array", - ); -} + ][::std::mem::offset_of!(Nice, large_array) - 8usize]; +}; impl Default for Nice { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -34,24 +26,3 @@ impl Default for Nice { } } } -impl ::std::fmt::Debug for Nice { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!( - f, - "Nice {{ pointer: {:?}, large_array: [{}] }}", - self.pointer, - { - use std::fmt::Write as _; - let mut output = String::new(); - let mut iter = self.large_array.iter(); - if let Some(value) = iter.next() { - let _ = write!(output, "{value:?}"); - for value in iter { - let _ = write!(output, ", {value:?}"); - } - } - output - }, - ) - } -} diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs index de6ce385ac..86e530463f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs @@ -1,5 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Debug)] pub struct Generic { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub t: [T; 40usize], @@ -13,8 +14,3 @@ impl Default for Generic { } } } -impl ::std::fmt::Debug for Generic { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "Generic {{ t: Array with length 40 }}") - } -} diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index d586278614..ac564a3cf6 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -1,20 +1,24 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/// If Bindgen could only determine the size and alignment of a +/// type, it is represented like this. +#[derive(PartialEq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct Instance { - pub val: [u32; 50usize], +pub struct __BindgenOpaqueArray(pub [T; N]); +impl Default for __BindgenOpaqueArray { + fn default() -> Self { + Self([::default(); N]) + } } -#[test] -fn bindgen_test_layout_Instance() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 200usize, "Size of Instance"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Instance"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - "Offset of field: Instance::val", - ); +#[repr(C)] +pub struct Instance { + pub val: __BindgenOpaqueArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Instance"][::std::mem::size_of::() - 200usize]; + ["Alignment of Instance"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Instance::val"][::std::mem::offset_of!(Instance, val) - 0usize]; +}; impl Default for Instance { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs index 13ddfd5ada..c8b3f10b93 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs @@ -4,11 +4,11 @@ pub struct Opaque { pub _bindgen_opaque_blob: [u32; 41usize], } -#[test] -fn bindgen_test_layout_Opaque() { - assert_eq!(::std::mem::size_of::(), 164usize, "Size of Opaque"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Opaque"); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Opaque"][::std::mem::size_of::() - 164usize]; + ["Alignment of Opaque"][::std::mem::align_of::() - 4usize]; +}; impl Default for Opaque { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -27,18 +27,14 @@ impl ::std::fmt::Debug for Opaque { pub struct OpaqueUser { pub opaque: Opaque, } -#[test] -fn bindgen_test_layout_OpaqueUser() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 164usize, "Size of OpaqueUser"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of OpaqueUser"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of OpaqueUser"][::std::mem::size_of::() - 164usize]; + ["Alignment of OpaqueUser"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: OpaqueUser::opaque", - ); -} + ][::std::mem::offset_of!(OpaqueUser, opaque) - 0usize]; +}; impl Default for OpaqueUser { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs index d0768416ec..3ca262fe36 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs @@ -1,21 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct Base { pub large: [::std::os::raw::c_int; 33usize], } -#[test] -fn bindgen_test_layout_Base() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 132usize, "Size of Base"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Base"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - "Offset of field: Base::large", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Base"][::std::mem::size_of::() - 132usize]; + ["Alignment of Base"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Base::large"][::std::mem::offset_of!(Base, large) - 0usize]; +}; impl Default for Base { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -25,29 +19,20 @@ impl Default for Base { } } } -impl ::std::cmp::PartialEq for Base { - fn eq(&self, other: &Base) -> bool { - &self.large[..] == &other.large[..] - } -} #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct ShouldDerivePartialEq { pub _base: Base, } -#[test] -fn bindgen_test_layout_ShouldDerivePartialEq() { - assert_eq!( - ::std::mem::size_of::(), - 132usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of ShouldDerivePartialEq", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 132usize]; + [ "Alignment of ShouldDerivePartialEq", - ); -} + ][::std::mem::align_of::() - 4usize]; +}; impl Default for ShouldDerivePartialEq { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -57,8 +42,3 @@ impl Default for ShouldDerivePartialEq { } } } -impl ::std::cmp::PartialEq for ShouldDerivePartialEq { - fn eq(&self, other: &ShouldDerivePartialEq) -> bool { - self._base == other._base - } -} diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index 7bcdce32a3..b8da88e2a7 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -32,6 +32,16 @@ where Self::extract_bit(byte, index) } #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; + Self::extract_bit(byte, index) + } + #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -49,6 +59,16 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize) + }; + unsafe { *byte = Self::change_bit(*byte, index, val) }; + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -69,6 +89,26 @@ where val } #[inline] + pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -86,25 +126,37 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } + #[inline] + pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; + } + } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 204usize, "Size of C"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 4usize, - "Offset of field: C::large_array", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 204usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::large_array"][::std::mem::offset_of!(C, large_array) - 4usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -114,12 +166,6 @@ impl Default for C { } } } -impl ::std::cmp::PartialEq for C { - fn eq(&self, other: &C) -> bool { - self.a() == other.a() && self.b() == other.b() - && &self.large_array[..] == &other.large_array[..] - } -} impl C { #[inline] pub fn a(&self) -> bool { @@ -133,6 +179,30 @@ impl C { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } @@ -144,6 +214,30 @@ impl C { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 7u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs index 3a7639f9de..9a36b8f8c7 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs @@ -1,22 +1,18 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct C { - pub large_array: [::std::os::raw::c_int; 420usize], + pub large_array: [::core::ffi::c_int; 420usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::core::mem::size_of::(), 1680usize, "Size of C"); - assert_eq!(::core::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::core::mem::size_of::() - 1680usize]; + ["Alignment of C"][::core::mem::align_of::() - 4usize]; + [ "Offset of field: C::large_array", - ); -} + ][::core::mem::offset_of!(C, large_array) - 0usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); @@ -26,8 +22,3 @@ impl Default for C { } } } -impl ::core::cmp::PartialEq for C { - fn eq(&self, other: &C) -> bool { - &self.large_array[..] == &other.large_array[..] - } -} diff --git a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs index c449e1a019..7085bef5c8 100644 --- a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs +++ b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs @@ -1,21 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct nsFoo { pub details: [f32; 400usize], } -#[test] -fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 1600usize, "Size of nsFoo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of nsFoo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize }, - 0usize, - "Offset of field: nsFoo::details", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsFoo"][::std::mem::size_of::() - 1600usize]; + ["Alignment of nsFoo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: nsFoo::details"][::std::mem::offset_of!(nsFoo, details) - 0usize]; +}; impl Default for nsFoo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -25,6 +19,6 @@ impl Default for nsFoo { } } } -extern "C" { +unsafe extern "C" { pub static gDetails: nsFoo; } diff --git a/bindgen-tests/tests/expectations/tests/extern_blocks_pre_1_82.rs b/bindgen-tests/tests/expectations/tests/extern_blocks_pre_1_82.rs index 9f684084ba..a322df78ce 100644 --- a/bindgen-tests/tests/expectations/tests/extern_blocks_pre_1_82.rs +++ b/bindgen-tests/tests/expectations/tests/extern_blocks_pre_1_82.rs @@ -1,7 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn cool_function(i: ::std::os::raw::c_int, c: ::std::os::raw::c_char); } -extern "C" { +unsafe extern "C" { pub static mut cool_static: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/i128.rs b/bindgen-tests/tests/expectations/tests/i128.rs index 87459b5e75..e29db491fe 100644 --- a/bindgen-tests/tests/expectations/tests/i128.rs +++ b/bindgen-tests/tests/expectations/tests/i128.rs @@ -6,20 +6,12 @@ pub struct foo { pub my_signed: i128, pub my_unsigned: u128, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 32usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::my_signed", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize }, - 16usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 32usize]; + ["Alignment of foo"][::std::mem::align_of::() - 16usize]; + ["Offset of field: foo::my_signed"][::std::mem::offset_of!(foo, my_signed) - 0usize]; + [ "Offset of field: foo::my_unsigned", - ); -} + ][::std::mem::offset_of!(foo, my_unsigned) - 16usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1291.rs b/bindgen-tests/tests/expectations/tests/issue-1291.rs index 190e899d7f..3c3fab3704 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1291.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1291.rs @@ -19,85 +19,35 @@ pub struct RTCRay { pub primID: ::std::os::raw::c_uint, pub instID: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_RTCRay() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 96usize, "Size of RTCRay"); - assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of RTCRay"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize }, - 0usize, - "Offset of field: RTCRay::org", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, - 12usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of RTCRay"][::std::mem::size_of::() - 96usize]; + ["Alignment of RTCRay"][::std::mem::align_of::() - 16usize]; + ["Offset of field: RTCRay::org"][::std::mem::offset_of!(RTCRay, org) - 0usize]; + [ "Offset of field: RTCRay::align0", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize }, - 16usize, - "Offset of field: RTCRay::dir", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, - 28usize, + ][::std::mem::offset_of!(RTCRay, align0) - 12usize]; + ["Offset of field: RTCRay::dir"][::std::mem::offset_of!(RTCRay, dir) - 16usize]; + [ "Offset of field: RTCRay::align1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, - 32usize, - "Offset of field: RTCRay::tnear", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize }, - 36usize, - "Offset of field: RTCRay::tfar", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, - 40usize, - "Offset of field: RTCRay::time", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 44usize, - "Offset of field: RTCRay::mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize }, - 48usize, - "Offset of field: RTCRay::Ng", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, - 60usize, + ][::std::mem::offset_of!(RTCRay, align1) - 28usize]; + ["Offset of field: RTCRay::tnear"][::std::mem::offset_of!(RTCRay, tnear) - 32usize]; + ["Offset of field: RTCRay::tfar"][::std::mem::offset_of!(RTCRay, tfar) - 36usize]; + ["Offset of field: RTCRay::time"][::std::mem::offset_of!(RTCRay, time) - 40usize]; + ["Offset of field: RTCRay::mask"][::std::mem::offset_of!(RTCRay, mask) - 44usize]; + ["Offset of field: RTCRay::Ng"][::std::mem::offset_of!(RTCRay, Ng) - 48usize]; + [ "Offset of field: RTCRay::align2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 64usize, - "Offset of field: RTCRay::u", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, - 68usize, - "Offset of field: RTCRay::v", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, - 72usize, + ][::std::mem::offset_of!(RTCRay, align2) - 60usize]; + ["Offset of field: RTCRay::u"][::std::mem::offset_of!(RTCRay, u) - 64usize]; + ["Offset of field: RTCRay::v"][::std::mem::offset_of!(RTCRay, v) - 68usize]; + [ "Offset of field: RTCRay::geomID", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, - 76usize, + ][::std::mem::offset_of!(RTCRay, geomID) - 72usize]; + [ "Offset of field: RTCRay::primID", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, - 80usize, + ][::std::mem::offset_of!(RTCRay, primID) - 76usize]; + [ "Offset of field: RTCRay::instID", - ); -} + ][::std::mem::offset_of!(RTCRay, instID) - 80usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index 80b8cbe8b6..62160d6351 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -1,6 +1,16 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { + /// If Bindgen could only determine the size and alignment of a + /// type, it is represented like this. + #[derive(PartialEq, Copy, Clone, Debug, Hash)] + #[repr(C)] + pub struct __BindgenOpaqueArray(pub [T; N]); + impl Default for __BindgenOpaqueArray { + fn default() -> Self { + Self([::default(); N]) + } + } #[allow(unused_imports)] use self::super::root; #[repr(C)] @@ -10,28 +20,14 @@ pub mod root { pub k: *mut root::i, pub l: bool, } - #[test] - fn bindgen_test_layout_i() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 24usize, "Size of i"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of i"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize }, - 0usize, - "Offset of field: i::j", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize }, - 8usize, - "Offset of field: i::k", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize }, - 16usize, - "Offset of field: i::l", - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of i"][::std::mem::size_of::() - 24usize]; + ["Alignment of i"][::std::mem::align_of::() - 8usize]; + ["Offset of field: i::j"][::std::mem::offset_of!(i, j) - 0usize]; + ["Offset of field: i::k"][::std::mem::offset_of!(i, k) - 8usize]; + ["Offset of field: i::l"][::std::mem::offset_of!(i, l) - 16usize]; + }; impl Default for i { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -46,18 +42,12 @@ pub mod root { pub struct d { pub m: root::i, } - #[test] - fn bindgen_test_layout_d() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 24usize, "Size of d"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of d"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 0usize, - "Offset of field: d::m", - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of d"][::std::mem::size_of::() - 24usize]; + ["Alignment of d"][::std::mem::align_of::() - 8usize]; + ["Offset of field: d::m"][::std::mem::offset_of!(d, m) - 0usize]; + }; impl Default for d { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -85,20 +75,14 @@ pub mod root { } #[repr(C)] pub struct F { - pub w: [u64; 33usize], - } - #[test] - fn bindgen_test_layout_F() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 264usize, "Size of F"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of F"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, - 0usize, - "Offset of field: F::w", - ); + pub w: root::__BindgenOpaqueArray, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of F"][::std::mem::size_of::() - 264usize]; + ["Alignment of F"][::std::mem::align_of::() - 8usize]; + ["Offset of field: F::w"][::std::mem::offset_of!(F, w) - 0usize]; + }; impl Default for F { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs b/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs index 0142673f3e..881cb9c8ed 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -7,44 +7,28 @@ pub struct AlignedToOne { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AlignedToOne() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of AlignedToOne"); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of AlignedToOne", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AlignedToOne"][::std::mem::size_of::() - 4usize]; + ["Alignment of AlignedToOne"][::std::mem::align_of::() - 1usize]; + [ "Offset of field: AlignedToOne::i", - ); -} + ][::std::mem::offset_of!(AlignedToOne, i) - 0usize]; +}; /// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AlignedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of AlignedToTwo"); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of AlignedToTwo", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AlignedToTwo"][::std::mem::size_of::() - 4usize]; + ["Alignment of AlignedToTwo"][::std::mem::align_of::() - 2usize]; + [ "Offset of field: AlignedToTwo::i", - ); -} + ][::std::mem::offset_of!(AlignedToTwo, i) - 0usize]; +}; /** This should not be opaque because although `libclang` doesn't give us the `#pragma pack(1)`, we can detect that alignment is 1 and add `#[repr(packed)]` to the struct ourselves.*/ @@ -54,27 +38,13 @@ pub struct PackedToOne { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_PackedToOne() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedToOne"); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of PackedToOne", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - "Offset of field: PackedToOne::x", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - "Offset of field: PackedToOne::y", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PackedToOne"][::std::mem::size_of::() - 8usize]; + ["Alignment of PackedToOne"][::std::mem::align_of::() - 1usize]; + ["Offset of field: PackedToOne::x"][::std::mem::offset_of!(PackedToOne, x) - 0usize]; + ["Offset of field: PackedToOne::y"][::std::mem::offset_of!(PackedToOne, y) - 4usize]; +}; /// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] @@ -82,24 +52,10 @@ pub struct PackedToTwo { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_PackedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedToTwo"); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of PackedToTwo", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - "Offset of field: PackedToTwo::x", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - "Offset of field: PackedToTwo::y", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PackedToTwo"][::std::mem::size_of::() - 8usize]; + ["Alignment of PackedToTwo"][::std::mem::align_of::() - 2usize]; + ["Offset of field: PackedToTwo::x"][::std::mem::offset_of!(PackedToTwo, x) - 0usize]; + ["Offset of field: PackedToTwo::y"][::std::mem::offset_of!(PackedToTwo, y) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index 08e47bc2c6..5d87159f97 100644 --- a/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -3,22 +3,16 @@ Debug/Hash because 63 is over the hard coded limit.*/ #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NoDebug { pub c: ::std::os::raw::c_char, } -#[test] -fn bindgen_test_layout_NoDebug() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 64usize, "Size of NoDebug"); - assert_eq!(::std::mem::align_of::(), 64usize, "Alignment of NoDebug"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - "Offset of field: NoDebug::c", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoDebug"][::std::mem::size_of::() - 64usize]; + ["Alignment of NoDebug"][::std::mem::align_of::() - 64usize]; + ["Offset of field: NoDebug::c"][::std::mem::offset_of!(NoDebug, c) - 0usize]; +}; impl Default for NoDebug { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -28,47 +22,32 @@ impl Default for NoDebug { } } } -impl ::std::cmp::PartialEq for NoDebug { - fn eq(&self, other: &NoDebug) -> bool { - self.c == other.c - } -} /** This should derive Debug/Hash/PartialEq/Eq because the padding size is less than the max derive Debug/Hash/PartialEq/Eq impl for arrays. However, we conservatively don't derive Debug/Hash because we determine Debug derive-ability before we compute padding, which happens at codegen.*/ #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ShouldDeriveDebugButDoesNot { pub c: [::std::os::raw::c_char; 32usize], pub d: ::std::os::raw::c_char, } -#[test] -fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 64usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of ShouldDeriveDebugButDoesNot", - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, + ][::std::mem::size_of::() - 64usize]; + [ "Alignment of ShouldDeriveDebugButDoesNot", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 64usize]; + [ "Offset of field: ShouldDeriveDebugButDoesNot::c", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(ShouldDeriveDebugButDoesNot, c) - 0usize]; + [ "Offset of field: ShouldDeriveDebugButDoesNot::d", - ); -} + ][::std::mem::offset_of!(ShouldDeriveDebugButDoesNot, d) - 32usize]; +}; impl Default for ShouldDeriveDebugButDoesNot { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -78,8 +57,3 @@ impl Default for ShouldDeriveDebugButDoesNot { } } } -impl ::std::cmp::PartialEq for ShouldDeriveDebugButDoesNot { - fn eq(&self, other: &ShouldDeriveDebugButDoesNot) -> bool { - self.c == other.c && self.d == other.d - } -} diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index b910159beb..a2805b7060 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -46,7 +46,7 @@ pub type rte_mempool_get_count = ::std::option::Option< /// Structure defining mempool operations structure #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mempool_ops { ///< Name of mempool ops struct. pub name: [::std::os::raw::c_char; 32usize], @@ -61,51 +61,31 @@ pub struct rte_mempool_ops { ///< Get qty of available objs. pub get_count: rte_mempool_get_count, } -#[test] -fn bindgen_test_layout_rte_mempool_ops() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - "Size of rte_mempool_ops", - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_mempool_ops"][::std::mem::size_of::() - 128usize]; + [ "Alignment of rte_mempool_ops", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 64usize]; + [ "Offset of field: rte_mempool_ops::name", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(rte_mempool_ops, name) - 0usize]; + [ "Offset of field: rte_mempool_ops::alloc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, - 40usize, + ][::std::mem::offset_of!(rte_mempool_ops, alloc) - 32usize]; + [ "Offset of field: rte_mempool_ops::free", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, - 48usize, + ][::std::mem::offset_of!(rte_mempool_ops, free) - 40usize]; + [ "Offset of field: rte_mempool_ops::enqueue", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, - 56usize, + ][::std::mem::offset_of!(rte_mempool_ops, enqueue) - 48usize]; + [ "Offset of field: rte_mempool_ops::dequeue", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(rte_mempool_ops, dequeue) - 56usize]; + [ "Offset of field: rte_mempool_ops::get_count", - ); -} + ][::std::mem::offset_of!(rte_mempool_ops, get_count) - 64usize]; +}; impl Default for rte_mempool_ops { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -115,13 +95,6 @@ impl Default for rte_mempool_ops { } } } -impl ::std::cmp::PartialEq for rte_mempool_ops { - fn eq(&self, other: &rte_mempool_ops) -> bool { - self.name == other.name && self.alloc == other.alloc && self.free == other.free - && self.enqueue == other.enqueue && self.dequeue == other.dequeue - && self.get_count == other.get_count - } -} /// The rte_spinlock_t type. #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -129,26 +102,14 @@ pub struct rte_spinlock_t { ///< lock status 0 = unlocked, 1 = locked pub locked: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_rte_spinlock_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_spinlock_t", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_spinlock_t", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_spinlock_t"][::std::mem::size_of::() - 4usize]; + ["Alignment of rte_spinlock_t"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_spinlock_t::locked", - ); -} + ][::std::mem::offset_of!(rte_spinlock_t, locked) - 0usize]; +}; /** Structure storing the table of registered ops structs, each of which contain the function pointers for the mempool ops functions. Each process has its own storage for this ops struct array so that @@ -158,7 +119,7 @@ fn bindgen_test_layout_rte_spinlock_t() { This results in us simply having "ops_index" in the mempool struct.*/ #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mempool_ops_table { ///< Spinlock for add/delete. pub sl: rte_spinlock_t, @@ -168,36 +129,24 @@ pub struct rte_mempool_ops_table { /// Storage for all possible ops structs. pub ops: [rte_mempool_ops; 16usize], } -#[test] -fn bindgen_test_layout_rte_mempool_ops_table() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2112usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_mempool_ops_table", - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, + ][::std::mem::size_of::() - 2112usize]; + [ "Alignment of rte_mempool_ops_table", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 64usize]; + [ "Offset of field: rte_mempool_ops_table::sl", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_mempool_ops_table, sl) - 0usize]; + [ "Offset of field: rte_mempool_ops_table::num_ops", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(rte_mempool_ops_table, num_ops) - 4usize]; + [ "Offset of field: rte_mempool_ops_table::ops", - ); -} + ][::std::mem::offset_of!(rte_mempool_ops_table, ops) - 64usize]; +}; impl Default for rte_mempool_ops_table { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -210,7 +159,7 @@ impl Default for rte_mempool_ops_table { /// Structure to hold malloc heap #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct malloc_heap { pub lock: rte_spinlock_t, pub free_head: [malloc_heap__bindgen_ty_1; 13usize], @@ -222,26 +171,18 @@ pub struct malloc_heap { pub struct malloc_heap__bindgen_ty_1 { pub lh_first: *mut malloc_elem, } -#[test] -fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of malloc_heap__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 8usize]; + [ "Alignment of malloc_heap__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: malloc_heap__bindgen_ty_1::lh_first", - ); -} + ][::std::mem::offset_of!(malloc_heap__bindgen_ty_1, lh_first) - 0usize]; +}; impl Default for malloc_heap__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -251,37 +192,23 @@ impl Default for malloc_heap__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_malloc_heap() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 128usize, "Size of malloc_heap"); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - "Alignment of malloc_heap", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of malloc_heap"][::std::mem::size_of::() - 128usize]; + ["Alignment of malloc_heap"][::std::mem::align_of::() - 64usize]; + [ "Offset of field: malloc_heap::lock", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(malloc_heap, lock) - 0usize]; + [ "Offset of field: malloc_heap::free_head", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize }, - 112usize, + ][::std::mem::offset_of!(malloc_heap, free_head) - 8usize]; + [ "Offset of field: malloc_heap::alloc_count", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, - 120usize, + ][::std::mem::offset_of!(malloc_heap, alloc_count) - 112usize]; + [ "Offset of field: malloc_heap::total_size", - ); -} + ][::std::mem::offset_of!(malloc_heap, total_size) - 120usize]; +}; impl Default for malloc_heap { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -291,13 +218,6 @@ impl Default for malloc_heap { } } } -impl ::std::cmp::PartialEq for malloc_heap { - fn eq(&self, other: &malloc_heap) -> bool { - self.lock == other.lock && self.free_head == other.free_head - && self.alloc_count == other.alloc_count - && self.total_size == other.total_size - } -} #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct malloc_elem { diff --git a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs index d6ce2883d7..315663e0fc 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs @@ -27,28 +27,14 @@ pub struct ip_frag { ///< fragment mbuf pub mb: *mut rte_mbuf, } -#[test] -fn bindgen_test_layout_ip_frag() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_frag"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of ip_frag"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, - 0usize, - "Offset of field: ip_frag::ofs", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 2usize, - "Offset of field: ip_frag::len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, - 8usize, - "Offset of field: ip_frag::mb", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag"][::std::mem::size_of::() - 16usize]; + ["Alignment of ip_frag"][::std::mem::align_of::() - 8usize]; + ["Offset of field: ip_frag::ofs"][::std::mem::offset_of!(ip_frag, ofs) - 0usize]; + ["Offset of field: ip_frag::len"][::std::mem::offset_of!(ip_frag, len) - 2usize]; + ["Offset of field: ip_frag::mb"][::std::mem::offset_of!(ip_frag, mb) - 8usize]; +}; impl Default for ip_frag { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -69,37 +55,25 @@ pub struct ip_frag_key { ///< src/dst key length pub key_len: u32, } -#[test] -fn bindgen_test_layout_ip_frag_key() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 40usize, "Size of ip_frag_key"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of ip_frag_key", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag_key"][::std::mem::size_of::() - 40usize]; + ["Alignment of ip_frag_key"][::std::mem::align_of::() - 8usize]; + [ "Offset of field: ip_frag_key::src_dst", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(ip_frag_key, src_dst) - 0usize]; + [ "Offset of field: ip_frag_key::id", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, - 36usize, + ][::std::mem::offset_of!(ip_frag_key, id) - 32usize]; + [ "Offset of field: ip_frag_key::key_len", - ); -} + ][::std::mem::offset_of!(ip_frag_key, key_len) - 36usize]; +}; /** @internal Fragmented packet to reassemble. First two entries in the frags[] array are for the last and first fragments.*/ #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ip_frag_pkt { ///< LRU list pub lru: ip_frag_pkt__bindgen_ty_1, @@ -122,31 +96,21 @@ pub struct ip_frag_pkt__bindgen_ty_1 { pub tqe_next: *mut ip_frag_pkt, pub tqe_prev: *mut *mut ip_frag_pkt, } -#[test] -fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of ip_frag_pkt__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 16usize]; + [ "Alignment of ip_frag_pkt__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_next", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(ip_frag_pkt__bindgen_ty_1, tqe_next) - 0usize]; + [ "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_prev", - ); -} + ][::std::mem::offset_of!(ip_frag_pkt__bindgen_ty_1, tqe_prev) - 8usize]; +}; impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -156,52 +120,32 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_ip_frag_pkt() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 192usize, "Size of ip_frag_pkt"); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - "Alignment of ip_frag_pkt", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag_pkt"][::std::mem::size_of::() - 192usize]; + ["Alignment of ip_frag_pkt"][::std::mem::align_of::() - 64usize]; + [ "Offset of field: ip_frag_pkt::lru", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(ip_frag_pkt, lru) - 0usize]; + [ "Offset of field: ip_frag_pkt::key", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, - 56usize, + ][::std::mem::offset_of!(ip_frag_pkt, key) - 16usize]; + [ "Offset of field: ip_frag_pkt::start", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(ip_frag_pkt, start) - 56usize]; + [ "Offset of field: ip_frag_pkt::total_size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, - 68usize, + ][::std::mem::offset_of!(ip_frag_pkt, total_size) - 64usize]; + [ "Offset of field: ip_frag_pkt::frag_size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, - 72usize, + ][::std::mem::offset_of!(ip_frag_pkt, frag_size) - 68usize]; + [ "Offset of field: ip_frag_pkt::last_idx", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, - 80usize, + ][::std::mem::offset_of!(ip_frag_pkt, last_idx) - 72usize]; + [ "Offset of field: ip_frag_pkt::frags", - ); -} + ][::std::mem::offset_of!(ip_frag_pkt, frags) - 80usize]; +}; impl Default for ip_frag_pkt { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -211,13 +155,6 @@ impl Default for ip_frag_pkt { } } } -impl ::std::cmp::PartialEq for ip_frag_pkt { - fn eq(&self, other: &ip_frag_pkt) -> bool { - self.lru == other.lru && self.key == other.key && self.start == other.start - && self.total_size == other.total_size && self.frag_size == other.frag_size - && self.last_idx == other.last_idx && self.frags == other.frags - } -} ///< fragment mbuf #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 2686d8f5fa..7d975cd979 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -32,6 +32,16 @@ where Self::extract_bit(byte, index) } #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; + Self::extract_bit(byte, index) + } + #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -49,6 +59,16 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + let byte_index = index / 8; + let byte = unsafe { + (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize) + }; + unsafe { *byte = Self::change_bit(*byte, index, val) }; + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -69,6 +89,26 @@ where val } #[inline] + pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -86,6 +126,24 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } + #[inline] + pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; + } + } } pub const ETH_MQ_RX_RSS_FLAG: u32 = 1; pub const ETH_MQ_RX_DCB_FLAG: u32 = 2; @@ -153,36 +211,20 @@ pub struct rte_eth_rxmode { pub split_hdr_size: u16, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } -#[test] -fn bindgen_test_layout_rte_eth_rxmode() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - "Size of rte_eth_rxmode", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_rxmode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_rxmode"][::std::mem::size_of::() - 12usize]; + ["Alignment of rte_eth_rxmode"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_rxmode::mq_mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_rxmode, mq_mode) - 0usize]; + [ "Offset of field: rte_eth_rxmode::max_rx_pkt_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_rxmode, max_rx_pkt_len) - 4usize]; + [ "Offset of field: rte_eth_rxmode::split_hdr_size", - ); -} + ][::std::mem::offset_of!(rte_eth_rxmode, split_hdr_size) - 8usize]; +}; impl Default for rte_eth_rxmode { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -205,6 +247,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn header_split_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_header_split_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_ip_checksum(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } @@ -216,6 +283,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn hw_ip_checksum_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_hw_ip_checksum_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_vlan_filter(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } @@ -227,6 +319,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn hw_vlan_filter_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_hw_vlan_filter_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 2usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_vlan_strip(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } @@ -238,6 +355,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn hw_vlan_strip_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_hw_vlan_strip_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 3usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_vlan_extend(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } @@ -249,6 +391,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn hw_vlan_extend_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_hw_vlan_extend_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn jumbo_frame(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } @@ -260,6 +427,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn jumbo_frame_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_jumbo_frame_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 5usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_strip_crc(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } @@ -271,6 +463,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn hw_strip_crc_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_hw_strip_crc_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 6usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn enable_scatter(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } @@ -282,6 +499,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn enable_scatter_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_enable_scatter_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn enable_lro(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } @@ -293,6 +535,31 @@ impl rte_eth_rxmode { } } #[inline] + pub unsafe fn enable_lro_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_enable_lro_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( header_split: u16, hw_ip_checksum: u16, @@ -427,31 +694,17 @@ pub struct rte_eth_txmode { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: u8, } -#[test] -fn bindgen_test_layout_rte_eth_txmode() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_eth_txmode", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_txmode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_txmode"][::std::mem::size_of::() - 8usize]; + ["Alignment of rte_eth_txmode"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_txmode::mq_mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_txmode, mq_mode) - 0usize]; + [ "Offset of field: rte_eth_txmode::pvid", - ); -} + ][::std::mem::offset_of!(rte_eth_txmode, pvid) - 4usize]; +}; impl Default for rte_eth_txmode { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -474,6 +727,30 @@ impl rte_eth_txmode { } } #[inline] + pub unsafe fn hw_vlan_reject_tagged_raw(this: *const Self) -> u8 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_hw_vlan_reject_tagged_raw(this: *mut Self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -485,6 +762,30 @@ impl rte_eth_txmode { } } #[inline] + pub unsafe fn hw_vlan_reject_untagged_raw(this: *const Self) -> u8 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_hw_vlan_reject_untagged_raw(this: *mut Self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -496,6 +797,30 @@ impl rte_eth_txmode { } } #[inline] + pub unsafe fn hw_vlan_insert_pvid_raw(this: *const Self) -> u8 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_hw_vlan_insert_pvid_raw(this: *mut Self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 2usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( hw_vlan_reject_tagged: u8, hw_vlan_reject_untagged: u8, @@ -563,36 +888,22 @@ pub struct rte_eth_rss_conf { ///< Hash functions to apply - see below. pub rss_hf: u64, } -#[test] -fn bindgen_test_layout_rte_eth_rss_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - "Size of rte_eth_rss_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_rss_conf"][::std::mem::size_of::() - 24usize]; + [ "Alignment of rte_eth_rss_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_rss_conf::rss_key", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_rss_conf, rss_key) - 0usize]; + [ "Offset of field: rte_eth_rss_conf::rss_key_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_eth_rss_conf, rss_key_len) - 8usize]; + [ "Offset of field: rte_eth_rss_conf::rss_hf", - ); -} + ][::std::mem::offset_of!(rte_eth_rss_conf, rss_hf) - 16usize]; +}; impl Default for rte_eth_rss_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -636,7 +947,7 @@ pub enum rte_eth_nb_pools { A default pool may be used, if desired, to route all traffic which does not match the vlan filter rules.*/ #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf { ///< With DCB, 16 or 32 pools pub nb_queue_pools: rte_eth_nb_pools, @@ -658,78 +969,48 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { ///< Bitmask of pools for packet rx pub pools: u64, } -#[test] -fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_vmdq_dcb_conf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 16usize]; + [ "Alignment of rte_eth_vmdq_dcb_conf__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::vlan_id", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf__bindgen_ty_1, vlan_id) - 0usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::pools", - ); -} -#[test] -fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1040usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf__bindgen_ty_1, pools) - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_vmdq_dcb_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 1040usize]; + [ "Alignment of rte_eth_vmdq_dcb_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf::nb_queue_pools", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize - }, - 4usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf, nb_queue_pools) - 0usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf::enable_default_pool", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, - 5usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf, enable_default_pool) - 4usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf::default_pool", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, - 6usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf, default_pool) - 5usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf::nb_pool_maps", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf, nb_pool_maps) - 6usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf::pool_map", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 1032usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf, pool_map) - 8usize]; + [ "Offset of field: rte_eth_vmdq_dcb_conf::dcb_tc", - ); -} + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_conf, dcb_tc) - 1032usize]; +}; impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -747,31 +1028,21 @@ pub struct rte_eth_dcb_rx_conf { /// Traffic class each UP mapped to. pub dcb_tc: [u8; 8usize], } -#[test] -fn bindgen_test_layout_rte_eth_dcb_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_dcb_rx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 12usize]; + [ "Alignment of rte_eth_dcb_rx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_dcb_rx_conf::nb_tcs", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_dcb_rx_conf, nb_tcs) - 0usize]; + [ "Offset of field: rte_eth_dcb_rx_conf::dcb_tc", - ); -} + ][::std::mem::offset_of!(rte_eth_dcb_rx_conf, dcb_tc) - 4usize]; +}; impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -789,31 +1060,21 @@ pub struct rte_eth_vmdq_dcb_tx_conf { /// Traffic class each UP mapped to. pub dcb_tc: [u8; 8usize], } -#[test] -fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_vmdq_dcb_tx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 12usize]; + [ "Alignment of rte_eth_vmdq_dcb_tx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_vmdq_dcb_tx_conf::nb_queue_pools", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_tx_conf, nb_queue_pools) - 0usize]; + [ "Offset of field: rte_eth_vmdq_dcb_tx_conf::dcb_tc", - ); -} + ][::std::mem::offset_of!(rte_eth_vmdq_dcb_tx_conf, dcb_tc) - 4usize]; +}; impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -831,31 +1092,21 @@ pub struct rte_eth_dcb_tx_conf { /// Traffic class each UP mapped to. pub dcb_tc: [u8; 8usize], } -#[test] -fn bindgen_test_layout_rte_eth_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_dcb_tx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 12usize]; + [ "Alignment of rte_eth_dcb_tx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_dcb_tx_conf::nb_tcs", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_dcb_tx_conf, nb_tcs) - 0usize]; + [ "Offset of field: rte_eth_dcb_tx_conf::dcb_tc", - ); -} + ][::std::mem::offset_of!(rte_eth_dcb_tx_conf, dcb_tc) - 4usize]; +}; impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -871,26 +1122,18 @@ pub struct rte_eth_vmdq_tx_conf { ///< VMDq mode, 64 pools. pub nb_queue_pools: rte_eth_nb_pools, } -#[test] -fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_vmdq_tx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 4usize]; + [ "Alignment of rte_eth_vmdq_tx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_vmdq_tx_conf::nb_queue_pools", - ); -} + ][::std::mem::offset_of!(rte_eth_vmdq_tx_conf, nb_queue_pools) - 0usize]; +}; impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -901,7 +1144,7 @@ impl Default for rte_eth_vmdq_tx_conf { } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf { ///< VMDq only mode, 8 or 64 pools pub nb_queue_pools: rte_eth_nb_pools, @@ -926,83 +1169,51 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { ///< Bitmask of pools for packet rx pub pools: u64, } -#[test] -fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_vmdq_rx_conf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 16usize]; + [ "Alignment of rte_eth_vmdq_rx_conf__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::vlan_id", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf__bindgen_ty_1, vlan_id) - 0usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::pools", - ); -} -#[test] -fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1040usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf__bindgen_ty_1, pools) - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_vmdq_rx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 1040usize]; + [ "Alignment of rte_eth_vmdq_rx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::nb_queue_pools", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize - }, - 4usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, nb_queue_pools) - 0usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::enable_default_pool", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, - 5usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, enable_default_pool) - 4usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::default_pool", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, - 6usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, default_pool) - 5usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::enable_loop_back", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, - 7usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, enable_loop_back) - 6usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::nb_pool_maps", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, nb_pool_maps) - 7usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::rx_mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, rx_mode) - 8usize]; + [ "Offset of field: rte_eth_vmdq_rx_conf::pool_map", - ); -} + ][::std::mem::offset_of!(rte_eth_vmdq_rx_conf, pool_map) - 16usize]; +}; impl Default for rte_eth_vmdq_rx_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -1065,46 +1276,28 @@ pub struct rte_eth_ipv4_flow { ///< Protocol, next header in big endian. pub proto: u8, } -#[test] -fn bindgen_test_layout_rte_eth_ipv4_flow() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - "Size of rte_eth_ipv4_flow", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_ipv4_flow"][::std::mem::size_of::() - 12usize]; + [ "Alignment of rte_eth_ipv4_flow", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_ipv4_flow::src_ip", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_ipv4_flow, src_ip) - 0usize]; + [ "Offset of field: rte_eth_ipv4_flow::dst_ip", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_eth_ipv4_flow, dst_ip) - 4usize]; + [ "Offset of field: rte_eth_ipv4_flow::tos", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, - 9usize, + ][::std::mem::offset_of!(rte_eth_ipv4_flow, tos) - 8usize]; + [ "Offset of field: rte_eth_ipv4_flow::ttl", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 10usize, + ][::std::mem::offset_of!(rte_eth_ipv4_flow, ttl) - 9usize]; + [ "Offset of field: rte_eth_ipv4_flow::proto", - ); -} + ][::std::mem::offset_of!(rte_eth_ipv4_flow, proto) - 10usize]; +}; /// A structure used to define the input for IPV6 flow #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -1120,46 +1313,28 @@ pub struct rte_eth_ipv6_flow { ///< Hop limits to match. pub hop_limits: u8, } -#[test] -fn bindgen_test_layout_rte_eth_ipv6_flow() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - "Size of rte_eth_ipv6_flow", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_ipv6_flow"][::std::mem::size_of::() - 36usize]; + [ "Alignment of rte_eth_ipv6_flow", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_ipv6_flow::src_ip", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_eth_ipv6_flow, src_ip) - 0usize]; + [ "Offset of field: rte_eth_ipv6_flow::dst_ip", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(rte_eth_ipv6_flow, dst_ip) - 16usize]; + [ "Offset of field: rte_eth_ipv6_flow::tc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 33usize, + ][::std::mem::offset_of!(rte_eth_ipv6_flow, tc) - 32usize]; + [ "Offset of field: rte_eth_ipv6_flow::proto", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, - 34usize, + ][::std::mem::offset_of!(rte_eth_ipv6_flow, proto) - 33usize]; + [ "Offset of field: rte_eth_ipv6_flow::hop_limits", - ); -} + ][::std::mem::offset_of!(rte_eth_ipv6_flow, hop_limits) - 34usize]; +}; /** A structure used to configure FDIR masks that are used by the device to match the various fields of RX packet headers.*/ #[repr(C)] @@ -1184,63 +1359,39 @@ first byte on the wire*/ 0 - Ignore tunnel type.*/ pub tunnel_type_mask: u8, } -#[test] -fn bindgen_test_layout_rte_eth_fdir_masks() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 68usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_fdir_masks", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 68usize]; + [ "Alignment of rte_eth_fdir_masks", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_fdir_masks::vlan_tci_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, vlan_tci_mask) - 0usize]; + [ "Offset of field: rte_eth_fdir_masks::ipv4_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, ipv4_mask) - 4usize]; + [ "Offset of field: rte_eth_fdir_masks::ipv6_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, - 52usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, ipv6_mask) - 16usize]; + [ "Offset of field: rte_eth_fdir_masks::src_port_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, - 54usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, src_port_mask) - 52usize]; + [ "Offset of field: rte_eth_fdir_masks::dst_port_mask", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize - }, - 56usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, dst_port_mask) - 54usize]; + [ "Offset of field: rte_eth_fdir_masks::mac_addr_byte_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, - 60usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, mac_addr_byte_mask) - 56usize]; + [ "Offset of field: rte_eth_fdir_masks::tunnel_id_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(rte_eth_fdir_masks, tunnel_id_mask) - 60usize]; + [ "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", - ); -} + ][::std::mem::offset_of!(rte_eth_fdir_masks, tunnel_type_mask) - 64usize]; +}; #[repr(u32)] /// Payload type #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -1261,31 +1412,21 @@ pub struct rte_eth_flex_payload_cfg { pub type_: rte_eth_payload_type, pub src_offset: [u16; 16usize], } -#[test] -fn bindgen_test_layout_rte_eth_flex_payload_cfg() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_flex_payload_cfg", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 36usize]; + [ "Alignment of rte_eth_flex_payload_cfg", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_flex_payload_cfg::type_", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_flex_payload_cfg, type_) - 0usize]; + [ "Offset of field: rte_eth_flex_payload_cfg::src_offset", - ); -} + ][::std::mem::offset_of!(rte_eth_flex_payload_cfg, src_offset) - 4usize]; +}; impl Default for rte_eth_flex_payload_cfg { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -1303,31 +1444,21 @@ pub struct rte_eth_fdir_flex_mask { pub flow_type: u16, pub mask: [u8; 16usize], } -#[test] -fn bindgen_test_layout_rte_eth_fdir_flex_mask() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 18usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_fdir_flex_mask", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, + ][::std::mem::size_of::() - 18usize]; + [ "Alignment of rte_eth_fdir_flex_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 2usize]; + [ "Offset of field: rte_eth_fdir_flex_mask::flow_type", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 2usize, + ][::std::mem::offset_of!(rte_eth_fdir_flex_mask, flow_type) - 0usize]; + [ "Offset of field: rte_eth_fdir_flex_mask::mask", - ); -} + ][::std::mem::offset_of!(rte_eth_fdir_flex_mask, mask) - 2usize]; +}; /** A structure used to define all flexible payload related setting include flex payload and flex mask*/ #[repr(C)] @@ -1340,41 +1471,27 @@ pub struct rte_eth_fdir_flex_conf { pub flex_set: [rte_eth_flex_payload_cfg; 8usize], pub flex_mask: [rte_eth_fdir_flex_mask; 22usize], } -#[test] -fn bindgen_test_layout_rte_eth_fdir_flex_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 688usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_fdir_flex_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 688usize]; + [ "Alignment of rte_eth_fdir_flex_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_fdir_flex_conf::nb_payloads", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, - 2usize, + ][::std::mem::offset_of!(rte_eth_fdir_flex_conf, nb_payloads) - 0usize]; + [ "Offset of field: rte_eth_fdir_flex_conf::nb_flexmasks", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_fdir_flex_conf, nb_flexmasks) - 2usize]; + [ "Offset of field: rte_eth_fdir_flex_conf::flex_set", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, - 292usize, + ][::std::mem::offset_of!(rte_eth_fdir_flex_conf, flex_set) - 4usize]; + [ "Offset of field: rte_eth_fdir_flex_conf::flex_mask", - ); -} + ][::std::mem::offset_of!(rte_eth_fdir_flex_conf, flex_mask) - 292usize]; +}; impl Default for rte_eth_fdir_flex_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -1402,51 +1519,29 @@ pub struct rte_fdir_conf { pub mask: rte_eth_fdir_masks, pub flex_conf: rte_eth_fdir_flex_conf, } -#[test] -fn bindgen_test_layout_rte_fdir_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 772usize, - "Size of rte_fdir_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_fdir_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_fdir_conf"][::std::mem::size_of::() - 772usize]; + ["Alignment of rte_fdir_conf"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_fdir_conf::mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_fdir_conf, mode) - 0usize]; + [ "Offset of field: rte_fdir_conf::pballoc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_fdir_conf, pballoc) - 4usize]; + [ "Offset of field: rte_fdir_conf::status", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, - 12usize, + ][::std::mem::offset_of!(rte_fdir_conf, status) - 8usize]; + [ "Offset of field: rte_fdir_conf::drop_queue", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_fdir_conf, drop_queue) - 12usize]; + [ "Offset of field: rte_fdir_conf::mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, - 84usize, + ][::std::mem::offset_of!(rte_fdir_conf, mask) - 16usize]; + [ "Offset of field: rte_fdir_conf::flex_conf", - ); -} + ][::std::mem::offset_of!(rte_fdir_conf, flex_conf) - 84usize]; +}; impl Default for rte_fdir_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -1465,27 +1560,17 @@ pub struct rte_intr_conf { /// enable/disable rxq interrupt. 0 (default) - disable, 1 enable pub rxq: u16, } -#[test] -fn bindgen_test_layout_rte_intr_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of rte_intr_conf"); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of rte_intr_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_intr_conf"][::std::mem::size_of::() - 4usize]; + ["Alignment of rte_intr_conf"][::std::mem::align_of::() - 2usize]; + [ "Offset of field: rte_intr_conf::lsc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, - 2usize, + ][::std::mem::offset_of!(rte_intr_conf, lsc) - 0usize]; + [ "Offset of field: rte_intr_conf::rxq", - ); -} + ][::std::mem::offset_of!(rte_intr_conf, rxq) - 2usize]; +}; /** A structure used to configure an Ethernet port. Depending upon the RX multi-queue mode, extra advanced configuration settings may be needed.*/ @@ -1523,7 +1608,7 @@ is needed,and the variable must be set ETH_DCB_PFC_SUPPORT.*/ pub intr_conf: rte_intr_conf, } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_conf__bindgen_ty_1 { ///< Port RSS configuration pub rss_conf: rte_eth_rss_conf, @@ -1531,41 +1616,27 @@ pub struct rte_eth_conf__bindgen_ty_1 { pub dcb_rx_conf: rte_eth_dcb_rx_conf, pub vmdq_rx_conf: rte_eth_vmdq_rx_conf, } -#[test] -fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2120usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_conf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 2120usize]; + [ "Alignment of rte_eth_conf__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_1::rss_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, - 24usize, + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_1, rss_conf) - 0usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_dcb_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, - 1064usize, + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_1, vmdq_dcb_conf) - 24usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_1::dcb_rx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, - 1080usize, + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_1, dcb_rx_conf) - 1064usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_rx_conf", - ); -} + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_1, vmdq_rx_conf) - 1080usize]; +}; impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -1582,36 +1653,24 @@ pub union rte_eth_conf__bindgen_ty_2 { pub dcb_tx_conf: rte_eth_dcb_tx_conf, pub vmdq_tx_conf: rte_eth_vmdq_tx_conf, } -#[test] -fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of rte_eth_conf__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 12usize]; + [ "Alignment of rte_eth_conf__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_dcb_tx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, - 0usize, + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_2, vmdq_dcb_tx_conf) - 0usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_2::dcb_tx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, - 0usize, + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_2, dcb_tx_conf) - 0usize]; + [ "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_tx_conf", - ); -} + ][::std::mem::offset_of!(rte_eth_conf__bindgen_ty_2, vmdq_tx_conf) - 0usize]; +}; impl Default for rte_eth_conf__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -1621,64 +1680,38 @@ impl Default for rte_eth_conf__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_rte_eth_conf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 2944usize, "Size of rte_eth_conf"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_eth_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_conf"][::std::mem::size_of::() - 2944usize]; + ["Alignment of rte_eth_conf"][::std::mem::align_of::() - 8usize]; + [ "Offset of field: rte_eth_conf::link_speeds", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, - 4usize, + ][::std::mem::offset_of!(rte_eth_conf, link_speeds) - 0usize]; + [ "Offset of field: rte_eth_conf::rxmode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_eth_conf, rxmode) - 4usize]; + [ "Offset of field: rte_eth_conf::txmode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, - 24usize, + ][::std::mem::offset_of!(rte_eth_conf, txmode) - 16usize]; + [ "Offset of field: rte_eth_conf::lpbk_mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(rte_eth_conf, lpbk_mode) - 24usize]; + [ "Offset of field: rte_eth_conf::rx_adv_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, - 2152usize, + ][::std::mem::offset_of!(rte_eth_conf, rx_adv_conf) - 32usize]; + [ "Offset of field: rte_eth_conf::tx_adv_conf", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize - }, - 2164usize, + ][::std::mem::offset_of!(rte_eth_conf, tx_adv_conf) - 2152usize]; + [ "Offset of field: rte_eth_conf::dcb_capability_en", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, - 2168usize, + ][::std::mem::offset_of!(rte_eth_conf, dcb_capability_en) - 2164usize]; + [ "Offset of field: rte_eth_conf::fdir_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, - 2940usize, + ][::std::mem::offset_of!(rte_eth_conf, fdir_conf) - 2168usize]; + [ "Offset of field: rte_eth_conf::intr_conf", - ); -} + ][::std::mem::offset_of!(rte_eth_conf, intr_conf) - 2940usize]; +}; impl Default for rte_eth_conf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs index a9d779e9a1..38f49fb4f0 100644 --- a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs @@ -3,7 +3,7 @@ pub const RTE_CACHE_LINE_MIN_SIZE: u32 = 64; pub const RTE_CACHE_LINE_SIZE: u32 = 64; #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct rte_kni_mbuf { pub buf_addr: *mut ::std::os::raw::c_void, pub buf_physaddr: u64, @@ -26,87 +26,53 @@ pub struct rte_kni_mbuf { pub pool: *mut ::std::os::raw::c_void, pub next: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_rte_kni_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 128usize, "Size of rte_kni_mbuf"); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - "Alignment of rte_kni_mbuf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_kni_mbuf"][::std::mem::size_of::() - 128usize]; + ["Alignment of rte_kni_mbuf"][::std::mem::align_of::() - 64usize]; + [ "Offset of field: rte_kni_mbuf::buf_addr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_kni_mbuf, buf_addr) - 0usize]; + [ "Offset of field: rte_kni_mbuf::buf_physaddr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_kni_mbuf, buf_physaddr) - 8usize]; + [ "Offset of field: rte_kni_mbuf::pad0", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, - 18usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pad0) - 16usize]; + [ "Offset of field: rte_kni_mbuf::data_off", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, - 20usize, + ][::std::mem::offset_of!(rte_kni_mbuf, data_off) - 18usize]; + [ "Offset of field: rte_kni_mbuf::pad1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pad1) - 20usize]; + [ "Offset of field: rte_kni_mbuf::nb_segs", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, - 23usize, + ][::std::mem::offset_of!(rte_kni_mbuf, nb_segs) - 22usize]; + [ "Offset of field: rte_kni_mbuf::pad4", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, - 24usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pad4) - 23usize]; + [ "Offset of field: rte_kni_mbuf::ol_flags", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(rte_kni_mbuf, ol_flags) - 24usize]; + [ "Offset of field: rte_kni_mbuf::pad2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pad2) - 32usize]; + [ "Offset of field: rte_kni_mbuf::pkt_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, - 40usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pkt_len) - 36usize]; + [ "Offset of field: rte_kni_mbuf::data_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(rte_kni_mbuf, data_len) - 40usize]; + [ "Offset of field: rte_kni_mbuf::pad3", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pad3) - 64usize]; + [ "Offset of field: rte_kni_mbuf::pool", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, + ][::std::mem::offset_of!(rte_kni_mbuf, pool) - 72usize]; + [ "Offset of field: rte_kni_mbuf::next", - ); -} + ][::std::mem::offset_of!(rte_kni_mbuf, next) - 80usize]; +}; impl Default for rte_kni_mbuf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); 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 b72c221dca..3be68eb925 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -57,28 +57,14 @@ pub struct ip_frag { ///< fragment mbuf pub mb: *mut rte_mbuf, } -#[test] -fn bindgen_test_layout_ip_frag() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_frag"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of ip_frag"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, - 0usize, - "Offset of field: ip_frag::ofs", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 2usize, - "Offset of field: ip_frag::len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, - 8usize, - "Offset of field: ip_frag::mb", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag"][::std::mem::size_of::() - 16usize]; + ["Alignment of ip_frag"][::std::mem::align_of::() - 8usize]; + ["Offset of field: ip_frag::ofs"][::std::mem::offset_of!(ip_frag, ofs) - 0usize]; + ["Offset of field: ip_frag::len"][::std::mem::offset_of!(ip_frag, len) - 2usize]; + ["Offset of field: ip_frag::mb"][::std::mem::offset_of!(ip_frag, mb) - 8usize]; +}; impl Default for ip_frag { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -99,37 +85,25 @@ pub struct ip_frag_key { ///< src/dst key length pub key_len: u32, } -#[test] -fn bindgen_test_layout_ip_frag_key() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 40usize, "Size of ip_frag_key"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of ip_frag_key", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag_key"][::std::mem::size_of::() - 40usize]; + ["Alignment of ip_frag_key"][::std::mem::align_of::() - 8usize]; + [ "Offset of field: ip_frag_key::src_dst", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(ip_frag_key, src_dst) - 0usize]; + [ "Offset of field: ip_frag_key::id", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, - 36usize, + ][::std::mem::offset_of!(ip_frag_key, id) - 32usize]; + [ "Offset of field: ip_frag_key::key_len", - ); -} + ][::std::mem::offset_of!(ip_frag_key, key_len) - 36usize]; +}; /** @internal Fragmented packet to reassemble. First two entries in the frags[] array are for the last and first fragments.*/ #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct ip_frag_pkt { ///< LRU list pub lru: ip_frag_pkt__bindgen_ty_1, @@ -152,31 +126,21 @@ pub struct ip_frag_pkt__bindgen_ty_1 { pub tqe_next: *mut ip_frag_pkt, pub tqe_prev: *mut *mut ip_frag_pkt, } -#[test] -fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of ip_frag_pkt__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 16usize]; + [ "Alignment of ip_frag_pkt__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_next", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(ip_frag_pkt__bindgen_ty_1, tqe_next) - 0usize]; + [ "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_prev", - ); -} + ][::std::mem::offset_of!(ip_frag_pkt__bindgen_ty_1, tqe_prev) - 8usize]; +}; impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -186,52 +150,32 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_ip_frag_pkt() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 192usize, "Size of ip_frag_pkt"); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - "Alignment of ip_frag_pkt", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag_pkt"][::std::mem::size_of::() - 192usize]; + ["Alignment of ip_frag_pkt"][::std::mem::align_of::() - 64usize]; + [ "Offset of field: ip_frag_pkt::lru", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(ip_frag_pkt, lru) - 0usize]; + [ "Offset of field: ip_frag_pkt::key", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, - 56usize, + ][::std::mem::offset_of!(ip_frag_pkt, key) - 16usize]; + [ "Offset of field: ip_frag_pkt::start", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(ip_frag_pkt, start) - 56usize]; + [ "Offset of field: ip_frag_pkt::total_size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, - 68usize, + ][::std::mem::offset_of!(ip_frag_pkt, total_size) - 64usize]; + [ "Offset of field: ip_frag_pkt::frag_size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, - 72usize, + ][::std::mem::offset_of!(ip_frag_pkt, frag_size) - 68usize]; + [ "Offset of field: ip_frag_pkt::last_idx", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, - 80usize, + ][::std::mem::offset_of!(ip_frag_pkt, last_idx) - 72usize]; + [ "Offset of field: ip_frag_pkt::frags", - ); -} + ][::std::mem::offset_of!(ip_frag_pkt, frags) - 80usize]; +}; impl Default for ip_frag_pkt { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -247,27 +191,17 @@ pub struct ip_pkt_list { pub tqh_first: *mut ip_frag_pkt, pub tqh_last: *mut *mut ip_frag_pkt, } -#[test] -fn bindgen_test_layout_ip_pkt_list() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_pkt_list"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of ip_pkt_list", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_pkt_list"][::std::mem::size_of::() - 16usize]; + ["Alignment of ip_pkt_list"][::std::mem::align_of::() - 8usize]; + [ "Offset of field: ip_pkt_list::tqh_first", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(ip_pkt_list, tqh_first) - 0usize]; + [ "Offset of field: ip_pkt_list::tqh_last", - ); -} + ][::std::mem::offset_of!(ip_pkt_list, tqh_last) - 8usize]; +}; impl Default for ip_pkt_list { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -280,7 +214,7 @@ impl Default for ip_pkt_list { /// fragmentation table statistics #[repr(C)] #[repr(align(64))] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct ip_frag_tbl_stat { ///< total # of find/insert attempts. pub find_num: u64, @@ -295,51 +229,31 @@ pub struct ip_frag_tbl_stat { ///< # of 'no space' add failures. pub fail_nospace: u64, } -#[test] -fn bindgen_test_layout_ip_frag_tbl_stat() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 64usize, - "Size of ip_frag_tbl_stat", - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ip_frag_tbl_stat"][::std::mem::size_of::() - 64usize]; + [ "Alignment of ip_frag_tbl_stat", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 64usize]; + [ "Offset of field: ip_frag_tbl_stat::find_num", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(ip_frag_tbl_stat, find_num) - 0usize]; + [ "Offset of field: ip_frag_tbl_stat::add_num", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(ip_frag_tbl_stat, add_num) - 8usize]; + [ "Offset of field: ip_frag_tbl_stat::del_num", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize }, - 24usize, + ][::std::mem::offset_of!(ip_frag_tbl_stat, del_num) - 16usize]; + [ "Offset of field: ip_frag_tbl_stat::reuse_num", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(ip_frag_tbl_stat, reuse_num) - 24usize]; + [ "Offset of field: ip_frag_tbl_stat::fail_total", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize }, - 40usize, + ][::std::mem::offset_of!(ip_frag_tbl_stat, fail_total) - 32usize]; + [ "Offset of field: ip_frag_tbl_stat::fail_nospace", - ); -} + ][::std::mem::offset_of!(ip_frag_tbl_stat, fail_nospace) - 40usize]; +}; impl Default for ip_frag_tbl_stat { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -352,6 +266,7 @@ impl Default for ip_frag_tbl_stat { /// fragmentation table #[repr(C)] #[repr(align(64))] +#[derive(Debug)] pub struct rte_ip_frag_tbl { ///< ttl for table entries. pub max_cycles: u64, @@ -377,76 +292,46 @@ pub struct rte_ip_frag_tbl { ///< hash table. pub pkt: __IncompleteArrayField, } -#[test] -fn bindgen_test_layout_rte_ip_frag_tbl() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - "Size of rte_ip_frag_tbl", - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_ip_frag_tbl"][::std::mem::size_of::() - 128usize]; + [ "Alignment of rte_ip_frag_tbl", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 64usize]; + [ "Offset of field: rte_ip_frag_tbl::max_cycles", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize }, - 8usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, max_cycles) - 0usize]; + [ "Offset of field: rte_ip_frag_tbl::entry_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize }, - 12usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, entry_mask) - 8usize]; + [ "Offset of field: rte_ip_frag_tbl::max_entries", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize }, - 16usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, max_entries) - 12usize]; + [ "Offset of field: rte_ip_frag_tbl::use_entries", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize }, - 20usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, use_entries) - 16usize]; + [ "Offset of field: rte_ip_frag_tbl::bucket_entries", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize }, - 24usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, bucket_entries) - 20usize]; + [ "Offset of field: rte_ip_frag_tbl::nb_entries", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize }, - 28usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, nb_entries) - 24usize]; + [ "Offset of field: rte_ip_frag_tbl::nb_buckets", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, - 32usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, nb_buckets) - 28usize]; + [ "Offset of field: rte_ip_frag_tbl::last", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, - 40usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, last) - 32usize]; + [ "Offset of field: rte_ip_frag_tbl::lru", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, - 64usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, lru) - 40usize]; + [ "Offset of field: rte_ip_frag_tbl::stat", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, - 128usize, + ][::std::mem::offset_of!(rte_ip_frag_tbl, stat) - 64usize]; + [ "Offset of field: rte_ip_frag_tbl::pkt", - ); -} + ][::std::mem::offset_of!(rte_ip_frag_tbl, pkt) - 128usize]; +}; impl Default for rte_ip_frag_tbl { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/long_double.rs b/bindgen-tests/tests/expectations/tests/long_double.rs index aa3109ca43..4a8b13e9b0 100644 --- a/bindgen-tests/tests/expectations/tests/long_double.rs +++ b/bindgen-tests/tests/expectations/tests/long_double.rs @@ -5,15 +5,9 @@ pub struct foo { pub bar: u128, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::bar", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 16usize]; + ["Alignment of foo"][::std::mem::align_of::() - 16usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs b/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs index d972c74376..ceec3823ae 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs @@ -1,5 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Debug)] pub struct Generic { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub t: [T; 40usize], @@ -13,11 +14,6 @@ impl Default for Generic { } } } -impl ::std::fmt::Debug for Generic { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "Generic {{ t: Array with length 40 }}") - } -} #[repr(C)] pub struct NoDebug { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, diff --git a/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs b/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs index 58f3684ac9..3dfd34474a 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs @@ -1,5 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Debug)] pub struct Generic { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub t: [T; 40usize], @@ -14,6 +15,7 @@ impl Default for Generic { } } #[repr(C)] +#[derive(Debug)] pub struct NoDefault { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub t: [T; 40usize], diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs index 4b070fa697..cc02195939 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs @@ -1,4 +1,14 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/// If Bindgen could only determine the size and alignment of a +/// type, it is represented like this. +#[derive(PartialEq, Copy, Clone, Debug, Hash)] +#[repr(C)] +pub struct __BindgenOpaqueArray(pub [T; N]); +impl Default for __BindgenOpaqueArray { + fn default() -> Self { + Self([::default(); N]) + } +} #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { @@ -8,34 +18,24 @@ pub struct OpaqueTemplate { Debug/Hash because the instantiation's definition cannot derive Debug/Hash.*/ #[repr(C)] pub struct ContainsOpaqueTemplate { - pub mBlah: [u32; 101usize], + pub mBlah: __BindgenOpaqueArray, pub mBaz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ContainsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 408usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of ContainsOpaqueTemplate", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, + ][::std::mem::size_of::() - 408usize]; + [ "Alignment of ContainsOpaqueTemplate", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, - 0usize, + ][::std::mem::align_of::() - 4usize]; + [ "Offset of field: ContainsOpaqueTemplate::mBlah", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, - 404usize, + ][::std::mem::offset_of!(ContainsOpaqueTemplate, mBlah) - 0usize]; + [ "Offset of field: ContainsOpaqueTemplate::mBaz", - ); -} + ][::std::mem::offset_of!(ContainsOpaqueTemplate, mBaz) - 404usize]; +}; impl Default for ContainsOpaqueTemplate { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -47,36 +47,28 @@ impl Default for ContainsOpaqueTemplate { } impl ::std::cmp::PartialEq for ContainsOpaqueTemplate { fn eq(&self, other: &ContainsOpaqueTemplate) -> bool { - &self.mBlah[..] == &other.mBlah[..] && self.mBaz == other.mBaz + self.mBlah == other.mBlah && self.mBaz == other.mBaz } } /** This should not end up deriving Debug/Hash either, for similar reasons, although we're exercising base member edges now.*/ #[repr(C)] pub struct InheritsOpaqueTemplate { - pub _base: [u8; 401usize], + pub _base: __BindgenOpaqueArray, pub wow: *mut ::std::os::raw::c_char, } -#[test] -fn bindgen_test_layout_InheritsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 416usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of InheritsOpaqueTemplate", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, + ][::std::mem::size_of::() - 416usize]; + [ "Alignment of InheritsOpaqueTemplate", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, - 408usize, + ][::std::mem::align_of::() - 8usize]; + [ "Offset of field: InheritsOpaqueTemplate::wow", - ); -} + ][::std::mem::offset_of!(InheritsOpaqueTemplate, wow) - 408usize]; +}; impl Default for InheritsOpaqueTemplate { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -88,6 +80,6 @@ impl Default for InheritsOpaqueTemplate { } impl ::std::cmp::PartialEq for InheritsOpaqueTemplate { fn eq(&self, other: &InheritsOpaqueTemplate) -> bool { - &self._base[..] == &other._base[..] && self.wow == other.wow + self._base == other._base && self.wow == other.wow } } diff --git a/bindgen-tests/tests/expectations/tests/packed-vtable.rs b/bindgen-tests/tests/expectations/tests/packed-vtable.rs index 362017a233..71e1956d88 100644 --- a/bindgen-tests/tests/expectations/tests/packed-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/packed-vtable.rs @@ -6,25 +6,21 @@ pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); pub struct PackedVtable { pub vtable_: *const PackedVtable__bindgen_vtable, } -#[test] -fn bindgen_test_layout_PackedVtable() { - assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedVtable"); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of PackedVtable", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PackedVtable"][::std::mem::size_of::() - 8usize]; + ["Alignment of PackedVtable"][::std::mem::align_of::() - 1usize]; +}; impl Default for PackedVtable { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN12PackedVtableD1Ev"] pub fn PackedVtable_PackedVtable_destructor(this: *mut PackedVtable); } diff --git a/bindgen-tests/tests/expectations/tests/repr-align.rs b/bindgen-tests/tests/expectations/tests/repr-align.rs index 6afc0ba859..867a28cc78 100644 --- a/bindgen-tests/tests/expectations/tests/repr-align.rs +++ b/bindgen-tests/tests/expectations/tests/repr-align.rs @@ -7,23 +7,13 @@ pub struct a { pub b: ::std::os::raw::c_int, pub c: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of a"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of a"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: a::b", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, - "Offset of field: a::c", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of a"][::std::mem::size_of::() - 8usize]; + ["Alignment of a"][::std::mem::align_of::() - 8usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; + ["Offset of field: a::c"][::std::mem::offset_of!(a, c) - 4usize]; +}; #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] @@ -31,20 +21,10 @@ pub struct b { pub b: ::std::os::raw::c_int, pub c: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_b() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of b"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of b"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: b::b", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, - "Offset of field: b::c", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of b"][::std::mem::size_of::() - 8usize]; + ["Alignment of b"][::std::mem::align_of::() - 8usize]; + ["Offset of field: b::b"][::std::mem::offset_of!(b, b) - 0usize]; + ["Offset of field: b::c"][::std::mem::offset_of!(b, c) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs index b472666081..f86fe6fb8f 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs @@ -4,39 +4,23 @@ pub struct LittleArray { pub a: [::std::os::raw::c_int; 32usize], } -#[test] -fn bindgen_test_layout_LittleArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 128usize, "Size of LittleArray"); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of LittleArray", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: LittleArray::a", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of LittleArray"][::std::mem::size_of::() - 128usize]; + ["Alignment of LittleArray"][::std::mem::align_of::() - 4usize]; + ["Offset of field: LittleArray::a"][::std::mem::offset_of!(LittleArray, a) - 0usize]; +}; #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct BigArray { pub a: [::std::os::raw::c_int; 33usize], } -#[test] -fn bindgen_test_layout_BigArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 132usize, "Size of BigArray"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of BigArray"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: BigArray::a", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of BigArray"][::std::mem::size_of::() - 132usize]; + ["Alignment of BigArray"][::std::mem::align_of::() - 4usize]; + ["Offset of field: BigArray::a"][::std::mem::offset_of!(BigArray, a) - 0usize]; +}; impl Default for BigArray { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -51,47 +35,27 @@ impl Default for BigArray { pub struct WithLittleArray { pub a: LittleArray, } -#[test] -fn bindgen_test_layout_WithLittleArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - "Size of WithLittleArray", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of WithLittleArray", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithLittleArray"][::std::mem::size_of::() - 128usize]; + ["Alignment of WithLittleArray"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: WithLittleArray::a", - ); -} + ][::std::mem::offset_of!(WithLittleArray, a) - 0usize]; +}; #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct WithBigArray { pub a: BigArray, } -#[test] -fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 132usize, "Size of WithBigArray"); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of WithBigArray", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithBigArray"][::std::mem::size_of::() - 132usize]; + ["Alignment of WithBigArray"][::std::mem::align_of::() - 4usize]; + [ "Offset of field: WithBigArray::a", - ); -} + ][::std::mem::offset_of!(WithBigArray, a) - 0usize]; +}; impl Default for WithBigArray { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs index eda7cadb46..df7a2192ed 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs @@ -1,21 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct S { pub large_array: [::std::os::raw::c_char; 33usize], } -#[test] -fn bindgen_test_layout_S() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 33usize, "Size of S"); - assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of S"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 0usize, - "Offset of field: S::large_array", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of S"][::std::mem::size_of::() - 33usize]; + ["Alignment of S"][::std::mem::align_of::() - 1usize]; + ["Offset of field: S::large_array"][::std::mem::offset_of!(S, large_array) - 0usize]; +}; impl Default for S { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -26,6 +20,7 @@ impl Default for S { } } #[repr(C)] +#[derive(Debug, Hash, PartialEq, Eq)] pub struct ST { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub large_array: [T; 33usize], diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index c626049b46..7a12f2abb7 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -51,10 +51,10 @@ pub struct StylePoint { } impl Default for StylePoint { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -84,10 +84,10 @@ pub struct StyleFoo_Foo_Body { } impl Default for StyleFoo_Foo_Body { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -100,10 +100,10 @@ pub struct StyleFoo_Bar_Body { } impl Default for StyleFoo_Bar_Body { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -116,10 +116,10 @@ pub struct StyleFoo_Baz_Body { } impl Default for StyleFoo_Baz_Body { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -130,19 +130,19 @@ pub struct StyleFoo__bindgen_ty_1 { } impl Default for StyleFoo__bindgen_ty_1 { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } impl Default for StyleFoo { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -167,10 +167,10 @@ pub struct StyleBar_StyleBar1_Body { } impl Default for StyleBar_StyleBar1_Body { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -182,10 +182,10 @@ pub struct StyleBar_StyleBar2_Body { } impl Default for StyleBar_StyleBar2_Body { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -197,10 +197,10 @@ pub struct StyleBar_StyleBar3_Body { } impl Default for StyleBar_StyleBar3_Body { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -215,45 +215,37 @@ pub struct StyleBar__bindgen_ty_1 { } impl Default for StyleBar__bindgen_ty_1 { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } impl Default for StyleBar { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } -#[test] -fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of template specialization: StylePoint_open0_float_close0", - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, + ][::std::mem::size_of::>() - 8usize]; + [ "Align of template specialization: StylePoint_open0_float_close0", - ); -} -#[test] -fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ "Size of template specialization: StylePoint_open0_float_close0", - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, + ][::std::mem::size_of::>() - 8usize]; + [ "Align of template specialization: StylePoint_open0_float_close0", - ); -} + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/union-align.rs b/bindgen-tests/tests/expectations/tests/union-align.rs index 2838ef34c3..bdb1bb376e 100644 --- a/bindgen-tests/tests/expectations/tests/union-align.rs +++ b/bindgen-tests/tests/expectations/tests/union-align.rs @@ -5,24 +5,18 @@ pub union Bar { pub foo: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of Bar"); - assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of Bar"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - "Offset of field: Bar::foo", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 16usize]; + ["Offset of field: Bar::foo"][::std::mem::offset_of!(Bar, foo) - 0usize]; +}; impl Default for Bar { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -32,24 +26,18 @@ impl Default for Bar { pub union Baz { pub bar: Bar, } -#[test] -fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of Baz"); - assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of Baz"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: Baz::bar", - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 16usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 16usize]; + ["Offset of field: Baz::bar"][::std::mem::offset_of!(Baz, bar) - 0usize]; +}; impl Default for Baz { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } diff --git a/bindgen-tests/tests/expectations/tests/win32-dtors.rs b/bindgen-tests/tests/expectations/tests/win32-dtors.rs index 042aa8cece..d7ed1290f8 100644 --- a/bindgen-tests/tests/expectations/tests/win32-dtors.rs +++ b/bindgen-tests/tests/expectations/tests/win32-dtors.rs @@ -4,32 +4,26 @@ pub struct CppObj { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_CppObj() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of CppObj"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of CppObj"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - "Offset of field: CppObj::x", - ); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of CppObj"][::std::mem::size_of::() - 4usize]; + ["Alignment of CppObj"][::std::mem::align_of::() - 4usize]; + ["Offset of field: CppObj::x"][::std::mem::offset_of!(CppObj, x) - 0usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}??0CppObj@@QEAA@H@Z"] pub fn CppObj_CppObj(this: *mut CppObj, x: ::std::os::raw::c_int); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}??1CppObj@@QEAA@XZ"] pub fn CppObj_CppObj_destructor(this: *mut CppObj); } impl CppObj { #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - CppObj_CppObj(&mut __bindgen_tmp, x); - __bindgen_tmp + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + CppObj_CppObj(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } #[inline] pub unsafe fn destruct(&mut self) { @@ -44,40 +38,34 @@ pub struct CppObj2 { pub vtable_: *const CppObj2__bindgen_vtable, pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_CppObj2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 16usize, "Size of CppObj2"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of CppObj2"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 8usize, - "Offset of field: CppObj2::x", - ); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of CppObj2"][::std::mem::size_of::() - 16usize]; + ["Alignment of CppObj2"][::std::mem::align_of::() - 8usize]; + ["Offset of field: CppObj2::x"][::std::mem::offset_of!(CppObj2, x) - 8usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}??0CppObj2@@QEAA@H@Z"] pub fn CppObj2_CppObj2(this: *mut CppObj2, x: ::std::os::raw::c_int); } impl Default for CppObj2 { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } impl CppObj2 { #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - CppObj2_CppObj2(&mut __bindgen_tmp, x); - __bindgen_tmp + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + CppObj2_CppObj2(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}??1CppObj2@@UEAA@XZ"] pub fn CppObj2_CppObj2_destructor(this: *mut CppObj2); } @@ -87,40 +75,34 @@ pub struct CppObj3 { pub _base: CppObj2, pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_CppObj3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 24usize, "Size of CppObj3"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of CppObj3"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 16usize, - "Offset of field: CppObj3::x", - ); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of CppObj3"][::std::mem::size_of::() - 24usize]; + ["Alignment of CppObj3"][::std::mem::align_of::() - 8usize]; + ["Offset of field: CppObj3::x"][::std::mem::offset_of!(CppObj3, x) - 16usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}??0CppObj3@@QEAA@H@Z"] pub fn CppObj3_CppObj3(this: *mut CppObj3, x: ::std::os::raw::c_int); } impl Default for CppObj3 { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } impl CppObj3 { #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - CppObj3_CppObj3(&mut __bindgen_tmp, x); - __bindgen_tmp + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + CppObj3_CppObj3(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}??1CppObj3@@UEAA@XZ"] pub fn CppObj3_CppObj3_destructor(this: *mut CppObj3); } @@ -130,40 +112,34 @@ pub struct CppObj4 { pub _base: CppObj2, pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_CppObj4() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 24usize, "Size of CppObj4"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of CppObj4"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 16usize, - "Offset of field: CppObj4::x", - ); -} -extern "C" { +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of CppObj4"][::std::mem::size_of::() - 24usize]; + ["Alignment of CppObj4"][::std::mem::align_of::() - 8usize]; + ["Offset of field: CppObj4::x"][::std::mem::offset_of!(CppObj4, x) - 16usize]; +}; +unsafe extern "C" { #[link_name = "\u{1}??0CppObj4@@QEAA@H@Z"] pub fn CppObj4_CppObj4(this: *mut CppObj4, x: ::std::os::raw::c_int); } impl Default for CppObj4 { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } impl CppObj4 { #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - CppObj4_CppObj4(&mut __bindgen_tmp, x); - __bindgen_tmp + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + CppObj4_CppObj4(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}??1CppObj4@@UEAA@XZ"] pub fn CppObj4_CppObj4_destructor(this: *mut CppObj4); } diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall.rs index d50348e799..aecdfbbf1f 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall.rs @@ -1,11 +1,33 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(not(test))] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); - assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "thiscall" { + #[link_name = "\u{1}?test@Foo@@QAEXXZ"] + pub fn Foo_test(this: *mut Foo); +} +unsafe extern "thiscall" { + #[link_name = "\u{1}?test2@Foo@@QAEHH@Z"] + pub fn Foo_test2( + this: *mut Foo, + var: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +impl Foo { + #[inline] + pub unsafe fn test(&mut self) { + Foo_test(self) + } + #[inline] + pub unsafe fn test2(&mut self, var: ::std::os::raw::c_int) -> ::std::os::raw::c_int { + Foo_test2(self, var) + } } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union.rs index 50cefed043..94bddf4c25 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union.rs @@ -26,19 +26,19 @@ pub union TErrorResult__bindgen_ty_1 { } impl Default for TErrorResult__bindgen_ty_1 { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } impl Default for TErrorResult { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } @@ -48,10 +48,10 @@ pub struct ErrorResult { } impl Default for ErrorResult { fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } } } diff --git a/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp index 258b6396de..bb9c3687e9 100644 --- a/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp +++ b/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: \-\-rust-target=1.33 --enable-function-attribute-detection +// bindgen-flags: --enable-function-attribute-detection class Foo { public: diff --git a/bindgen-tests/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp index a102cbf100..25127d9cd0 100644 --- a/bindgen-tests/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp +++ b/bindgen-tests/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp @@ -1,5 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 - class Foo { public: __attribute__((warn_unused_result)) diff --git a/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp b/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp index 78b05b4f92..4007e02566 100644 --- a/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp +++ b/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: \-\-rust-target=1.33 --enable-cxx-namespaces +// bindgen-flags: --enable-cxx-namespaces namespace foo { union Bar { diff --git a/bindgen-tests/tests/headers/bitfield-enum-repr-c.hpp b/bindgen-tests/tests/headers/bitfield-enum-repr-c.hpp index b80f5d99a5..da5fc961dd 100644 --- a/bindgen-tests/tests/headers/bitfield-enum-repr-c.hpp +++ b/bindgen-tests/tests/headers/bitfield-enum-repr-c.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --bitfield-enum "Foo" \-\-rust-target=1.33 -- -std=c++11 +// bindgen-flags: --bitfield-enum "Foo" -- -std=c++11 enum Foo { Bar = 1 << 1, diff --git a/bindgen-tests/tests/headers/bitfield-enum-repr-transparent.hpp b/bindgen-tests/tests/headers/bitfield-enum-repr-transparent.hpp index b80f5d99a5..1c58ff4eca 100644 --- a/bindgen-tests/tests/headers/bitfield-enum-repr-transparent.hpp +++ b/bindgen-tests/tests/headers/bitfield-enum-repr-transparent.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --bitfield-enum "Foo" \-\-rust-target=1.33 -- -std=c++11 +// bindgen-flags: --bitfield-enum "Foo" enum Foo { Bar = 1 << 1, diff --git a/bindgen-tests/tests/headers/class.hpp b/bindgen-tests/tests/headers/class.hpp index a90e373f77..f77ac92a66 100644 --- a/bindgen-tests/tests/headers/class.hpp +++ b/bindgen-tests/tests/headers/class.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --with-derive-partialord --with-derive-ord --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --with-derive-partialord --with-derive-ord // class C { int a; diff --git a/bindgen-tests/tests/headers/constructors_1_33.hpp b/bindgen-tests/tests/headers/constructors_1_33.hpp index e275f8907e..b16c8c35a3 100644 --- a/bindgen-tests/tests/headers/constructors_1_33.hpp +++ b/bindgen-tests/tests/headers/constructors_1_33.hpp @@ -1,5 +1,3 @@ -// bindgen-flags: --rust-target 1.33 - class TestOverload { // This one shouldn't be generated. TestOverload(); diff --git a/bindgen-tests/tests/headers/derive-bitfield-method-same-name.hpp b/bindgen-tests/tests/headers/derive-bitfield-method-same-name.hpp index ea9d801f4e..4b7b21e93a 100644 --- a/bindgen-tests/tests/headers/derive-bitfield-method-same-name.hpp +++ b/bindgen-tests/tests/headers/derive-bitfield-method-same-name.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq --impl-debug --rust-target 1.40 +// bindgen-flags: --with-derive-partialeq --impl-partialeq --impl-debug /// Because this struct have array larger than 32 items /// and --with-derive-partialeq --impl-partialeq --impl-debug is provided, diff --git a/bindgen-tests/tests/headers/derive-clone.h b/bindgen-tests/tests/headers/derive-clone.h index aacbcaf885..8dc30eacfc 100644 --- a/bindgen-tests/tests/headers/derive-clone.h +++ b/bindgen-tests/tests/headers/derive-clone.h @@ -1,6 +1,3 @@ -// bindgen-flags: --rust-target 1.40 -// - /// This struct should derive `Clone`. struct ShouldDeriveClone { int large[33]; diff --git a/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp b/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp index a68611d98b..df43e6a7c2 100644 --- a/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp +++ b/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --rust-target 1.51 +// bindgen-flags: --impl-debug class C { bool a: 1; diff --git a/bindgen-tests/tests/headers/derive-debug-bitfield-core.hpp b/bindgen-tests/tests/headers/derive-debug-bitfield-core.hpp index 2073cc2a0d..5d78e74359 100644 --- a/bindgen-tests/tests/headers/derive-debug-bitfield-core.hpp +++ b/bindgen-tests/tests/headers/derive-debug-bitfield-core.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --use-core --raw-line "extern crate core;" --rust-target 1.40 +// bindgen-flags: --impl-debug --use-core --raw-line "extern crate core;" class C { bool a: 1; diff --git a/bindgen-tests/tests/headers/derive-debug-bitfield.hpp b/bindgen-tests/tests/headers/derive-debug-bitfield.hpp index b68919054a..df43e6a7c2 100644 --- a/bindgen-tests/tests/headers/derive-debug-bitfield.hpp +++ b/bindgen-tests/tests/headers/derive-debug-bitfield.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --rust-target 1.40 +// bindgen-flags: --impl-debug class C { bool a: 1; diff --git a/bindgen-tests/tests/headers/derive-debug-function-pointer.hpp b/bindgen-tests/tests/headers/derive-debug-function-pointer.hpp index 147097fbd8..a370dee813 100644 --- a/bindgen-tests/tests/headers/derive-debug-function-pointer.hpp +++ b/bindgen-tests/tests/headers/derive-debug-function-pointer.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --rust-target 1.40 +// bindgen-flags: --impl-debug class Nice { typedef void (*Function) (int data); diff --git a/bindgen-tests/tests/headers/derive-debug-generic.hpp b/bindgen-tests/tests/headers/derive-debug-generic.hpp index 50122fafa5..d5158510ea 100644 --- a/bindgen-tests/tests/headers/derive-debug-generic.hpp +++ b/bindgen-tests/tests/headers/derive-debug-generic.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --rust-target 1.40 +// bindgen-flags: --impl-debug template class Generic { diff --git a/bindgen-tests/tests/headers/derive-debug-opaque-template-instantiation.hpp b/bindgen-tests/tests/headers/derive-debug-opaque-template-instantiation.hpp index 0c70fcc53a..0dead782ff 100644 --- a/bindgen-tests/tests/headers/derive-debug-opaque-template-instantiation.hpp +++ b/bindgen-tests/tests/headers/derive-debug-opaque-template-instantiation.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --rust-target 1.40 +// bindgen-flags: --impl-debug // This type is opaque because the second template parameter // is a non-type template parameter diff --git a/bindgen-tests/tests/headers/derive-debug-opaque.hpp b/bindgen-tests/tests/headers/derive-debug-opaque.hpp index 715d3c89f1..0ce1d63ab8 100644 --- a/bindgen-tests/tests/headers/derive-debug-opaque.hpp +++ b/bindgen-tests/tests/headers/derive-debug-opaque.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "Opaque" --impl-debug --rust-target 1.40 +// bindgen-flags: --opaque-type "Opaque" --impl-debug class Opaque { int i; diff --git a/bindgen-tests/tests/headers/derive-partialeq-base.hpp b/bindgen-tests/tests/headers/derive-partialeq-base.hpp index 2a57dca47d..989cbe693a 100644 --- a/bindgen-tests/tests/headers/derive-partialeq-base.hpp +++ b/bindgen-tests/tests/headers/derive-partialeq-base.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq --rust-target 1.40 +// bindgen-flags: --with-derive-partialeq --impl-partialeq class Base { int large[33]; diff --git a/bindgen-tests/tests/headers/derive-partialeq-bitfield.hpp b/bindgen-tests/tests/headers/derive-partialeq-bitfield.hpp index f6dd82e572..ac2cac632a 100644 --- a/bindgen-tests/tests/headers/derive-partialeq-bitfield.hpp +++ b/bindgen-tests/tests/headers/derive-partialeq-bitfield.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq --rust-target 1.40 +// bindgen-flags: --with-derive-partialeq --impl-partialeq class C { bool a: 1; diff --git a/bindgen-tests/tests/headers/derive-partialeq-core.h b/bindgen-tests/tests/headers/derive-partialeq-core.h index 18eed8b324..6da5b786bc 100644 --- a/bindgen-tests/tests/headers/derive-partialeq-core.h +++ b/bindgen-tests/tests/headers/derive-partialeq-core.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq --use-core --raw-line "extern crate core;" --rust-target 1.40 +// bindgen-flags: --with-derive-partialeq --impl-partialeq --use-core --raw-line "extern crate core;" struct C { int large_array[420]; diff --git a/bindgen-tests/tests/headers/extern-const-struct.h b/bindgen-tests/tests/headers/extern-const-struct.h index 1027127428..10006e8284 100644 --- a/bindgen-tests/tests/headers/extern-const-struct.h +++ b/bindgen-tests/tests/headers/extern-const-struct.h @@ -1,5 +1,3 @@ -// bindgen-flags: --rust-target 1.40 - struct nsFoo { float details[400]; }; diff --git a/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h b/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h index abed05d11f..604625a0a3 100644 --- a/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h +++ b/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h @@ -1,4 +1,4 @@ -// bindgen-flags: --no-layout-tests --rust-target=1.81 +// bindgen-flags: --no-layout-tests void cool_function(int i, char c); diff --git a/bindgen-tests/tests/headers/i128.h b/bindgen-tests/tests/headers/i128.h index 609d546190..1880f11305 100644 --- a/bindgen-tests/tests/headers/i128.h +++ b/bindgen-tests/tests/headers/i128.h @@ -1,5 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 - struct foo { __int128 my_signed; unsigned __int128 my_unsigned; diff --git a/bindgen-tests/tests/headers/issue-1291.hpp b/bindgen-tests/tests/headers/issue-1291.hpp index 313f7f7103..cb4aeb91f8 100644 --- a/bindgen-tests/tests/headers/issue-1291.hpp +++ b/bindgen-tests/tests/headers/issue-1291.hpp @@ -1,4 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 // bindgen-unstable struct __attribute__((aligned(16))) RTCRay diff --git a/bindgen-tests/tests/headers/issue-372.hpp b/bindgen-tests/tests/headers/issue-372.hpp index a2a5d45122..7127be2ccb 100644 --- a/bindgen-tests/tests/headers/issue-372.hpp +++ b/bindgen-tests/tests/headers/issue-372.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --rustified-enum ".*" --rust-target 1.40 +// bindgen-flags: --enable-cxx-namespaces --rustified-enum ".*" template class c { a e[b]; }; class d; template class C { c h; }; diff --git a/bindgen-tests/tests/headers/issue-537-repr-packed-n.h b/bindgen-tests/tests/headers/issue-537-repr-packed-n.h index 7beaf88383..40be004c85 100644 --- a/bindgen-tests/tests/headers/issue-537-repr-packed-n.h +++ b/bindgen-tests/tests/headers/issue-537-repr-packed-n.h @@ -1,4 +1,4 @@ -// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' --rust-target 1.33 +// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' /// This should not be opaque; we can see the attributes and can pack the /// struct. diff --git a/bindgen-tests/tests/headers/issue-648-derive-debug-with-padding.h b/bindgen-tests/tests/headers/issue-648-derive-debug-with-padding.h index 0860ce9502..d54fe374ce 100644 --- a/bindgen-tests/tests/headers/issue-648-derive-debug-with-padding.h +++ b/bindgen-tests/tests/headers/issue-648-derive-debug-with-padding.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq /** * We emit a `[u8; 63usize]` padding field for this struct, which cannot derive * Debug/Hash because 63 is over the hard coded limit. diff --git a/bindgen-tests/tests/headers/layout.h b/bindgen-tests/tests/headers/layout.h index 0b3df26347..06b7165ab9 100644 --- a/bindgen-tests/tests/headers/layout.h +++ b/bindgen-tests/tests/headers/layout.h @@ -1,5 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 -// // FIXME: https://github.com/rust-lang/rust-bindgen/issues/1498 diff --git a/bindgen-tests/tests/headers/layout_array.h b/bindgen-tests/tests/headers/layout_array.h index e6a57f7ca4..239e52b193 100644 --- a/bindgen-tests/tests/headers/layout_array.h +++ b/bindgen-tests/tests/headers/layout_array.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/bindgen-tests/tests/headers/layout_array_too_long.h b/bindgen-tests/tests/headers/layout_array_too_long.h index 53e4d8bed4..d0d34ba038 100644 --- a/bindgen-tests/tests/headers/layout_array_too_long.h +++ b/bindgen-tests/tests/headers/layout_array_too_long.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rustified-enum ".*" --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rustified-enum ".*" typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/bindgen-tests/tests/headers/layout_eth_conf.h b/bindgen-tests/tests/headers/layout_eth_conf.h index 1c821c9769..ec1a691985 100644 --- a/bindgen-tests/tests/headers/layout_eth_conf.h +++ b/bindgen-tests/tests/headers/layout_eth_conf.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/bindgen-tests/tests/headers/layout_kni_mbuf.h b/bindgen-tests/tests/headers/layout_kni_mbuf.h index 4d604aa6a8..148cb7df95 100644 --- a/bindgen-tests/tests/headers/layout_kni_mbuf.h +++ b/bindgen-tests/tests/headers/layout_kni_mbuf.h @@ -1,5 +1,3 @@ -// bindgen-flags: --rust-target 1.40 - #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */ #define RTE_CACHE_LINE_SIZE 64 diff --git a/bindgen-tests/tests/headers/layout_large_align_field.h b/bindgen-tests/tests/headers/layout_large_align_field.h index 63aea90bd9..f292bb70dc 100644 --- a/bindgen-tests/tests/headers/layout_large_align_field.h +++ b/bindgen-tests/tests/headers/layout_large_align_field.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rustified-enum ".*" --rust-target 1.40 +// bindgen-flags: --rustified-enum ".*" typedef unsigned char uint8_t; typedef unsigned short uint16_t; diff --git a/bindgen-tests/tests/headers/long_double.h b/bindgen-tests/tests/headers/long_double.h index c8872d6ebf..341be37164 100644 --- a/bindgen-tests/tests/headers/long_double.h +++ b/bindgen-tests/tests/headers/long_double.h @@ -1,5 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 - struct foo { long double bar; }; diff --git a/bindgen-tests/tests/headers/newtype-enum.hpp b/bindgen-tests/tests/headers/newtype-enum.hpp index 45f3303c8c..e711ed85bc 100644 --- a/bindgen-tests/tests/headers/newtype-enum.hpp +++ b/bindgen-tests/tests/headers/newtype-enum.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --newtype-enum "Foo" \-\-rust-target=1.33 -- -std=c++11 +// bindgen-flags: --newtype-enum "Foo" -- -std=c++11 enum Foo { Bar = 1 << 1, diff --git a/bindgen-tests/tests/headers/newtype-global-enum.hpp b/bindgen-tests/tests/headers/newtype-global-enum.hpp index e52b19b84a..c10825fdcf 100644 --- a/bindgen-tests/tests/headers/newtype-global-enum.hpp +++ b/bindgen-tests/tests/headers/newtype-global-enum.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --newtype-global-enum "Foo" \-\-rust-target=1.33 -- -std=c++11 +// bindgen-flags: --newtype-global-enum "Foo" -- -std=c++11 enum Foo { Bar = 1 << 1, diff --git a/bindgen-tests/tests/headers/no_debug_bypass_impl_debug.hpp b/bindgen-tests/tests/headers/no_debug_bypass_impl_debug.hpp index d934d2c7cb..a586441088 100644 --- a/bindgen-tests/tests/headers/no_debug_bypass_impl_debug.hpp +++ b/bindgen-tests/tests/headers/no_debug_bypass_impl_debug.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --no-debug "NoDebug" --impl-debug --rust-target 1.40 +// bindgen-flags: --no-debug "NoDebug" --impl-debug template class Generic { diff --git a/bindgen-tests/tests/headers/no_default_bypass_derive_default.hpp b/bindgen-tests/tests/headers/no_default_bypass_derive_default.hpp index ab0fdfae9f..0f8339062f 100644 --- a/bindgen-tests/tests/headers/no_default_bypass_derive_default.hpp +++ b/bindgen-tests/tests/headers/no_default_bypass_derive_default.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --no-default "NoDefault" --rust-target 1.40 +// bindgen-flags: --no-default "NoDefault" template class Generic { diff --git a/bindgen-tests/tests/headers/opaque-template-inst-member.hpp b/bindgen-tests/tests/headers/opaque-template-inst-member.hpp index 9b327919c1..6516aa564d 100644 --- a/bindgen-tests/tests/headers/opaque-template-inst-member.hpp +++ b/bindgen-tests/tests/headers/opaque-template-inst-member.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash --with-derive-partialeq --impl-partialeq --with-derive-eq --rust-target 1.40 +// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash --with-derive-partialeq --impl-partialeq --with-derive-eq template class OpaqueTemplate { diff --git a/bindgen-tests/tests/headers/packed-vtable.h b/bindgen-tests/tests/headers/packed-vtable.h index d2413d4571..b3405977b5 100644 --- a/bindgen-tests/tests/headers/packed-vtable.h +++ b/bindgen-tests/tests/headers/packed-vtable.h @@ -1,4 +1,4 @@ -// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' --rust-target 1.33 -- -x c++ -std=c++11 +// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' -- -x c++ -std=c++11 #pragma pack(1) diff --git a/bindgen-tests/tests/headers/repr-align.hpp b/bindgen-tests/tests/headers/repr-align.hpp index b3231d39bc..a7719e10ed 100644 --- a/bindgen-tests/tests/headers/repr-align.hpp +++ b/bindgen-tests/tests/headers/repr-align.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' \-\-rust-target=1.33 -- -std=c++11 +// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' -- -std=c++11 struct alignas(8) a { int b; diff --git a/bindgen-tests/tests/headers/strings_array.h b/bindgen-tests/tests/headers/strings_array.h index 212b0903a7..fa7bf561fa 100644 --- a/bindgen-tests/tests/headers/strings_array.h +++ b/bindgen-tests/tests/headers/strings_array.h @@ -1,5 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 - const char* MY_STRING_UTF8 = "Hello, world!"; const char* MY_STRING_INTERIOR_NULL = "Hello,\0World!"; const char* MY_STRING_NON_UTF8 = "ABCDE\xFF"; diff --git a/bindgen-tests/tests/headers/struct_with_derive_debug.h b/bindgen-tests/tests/headers/struct_with_derive_debug.h index 4dc816b787..201748d9c5 100644 --- a/bindgen-tests/tests/headers/struct_with_derive_debug.h +++ b/bindgen-tests/tests/headers/struct_with_derive_debug.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq // struct LittleArray { int a[32]; diff --git a/bindgen-tests/tests/headers/struct_with_large_array.hpp b/bindgen-tests/tests/headers/struct_with_large_array.hpp index 974ca526a3..58e8e4d19a 100644 --- a/bindgen-tests/tests/headers/struct_with_large_array.hpp +++ b/bindgen-tests/tests/headers/struct_with_large_array.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rust-target 1.40 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq // struct S { char large_array[33]; diff --git a/bindgen-tests/tests/headers/transform-op.hpp b/bindgen-tests/tests/headers/transform-op.hpp index 907a5a4657..090e88b34b 100644 --- a/bindgen-tests/tests/headers/transform-op.hpp +++ b/bindgen-tests/tests/headers/transform-op.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: \-\-rust-target=1.33 -- -std=c++11 +// bindgen-flags: -- -std=c++11 typedef unsigned char uint8_t; typedef int int32_t; diff --git a/bindgen-tests/tests/headers/union-align.h b/bindgen-tests/tests/headers/union-align.h index bfb5b5a199..5ed955f25e 100644 --- a/bindgen-tests/tests/headers/union-align.h +++ b/bindgen-tests/tests/headers/union-align.h @@ -1,5 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 - union Bar { unsigned char foo; } __attribute__ ((__aligned__ (16))); diff --git a/bindgen-tests/tests/headers/win32-dtors.hpp b/bindgen-tests/tests/headers/win32-dtors.hpp index 7faa5e9562..0f0f0e1604 100644 --- a/bindgen-tests/tests/headers/win32-dtors.hpp +++ b/bindgen-tests/tests/headers/win32-dtors.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: \-\-rust-target=1.33 -- --target=x86_64-pc-windows-msvc +// bindgen-flags: -- --target=x86_64-pc-windows-msvc struct CppObj { int x; @@ -26,4 +26,4 @@ struct CppObj4 : CppObj2 { CppObj4(int x); ~CppObj4(); -}; \ No newline at end of file +}; diff --git a/bindgen-tests/tests/headers/win32-thiscall.hpp b/bindgen-tests/tests/headers/win32-thiscall.hpp index d4e3976303..4651f809a1 100644 --- a/bindgen-tests/tests/headers/win32-thiscall.hpp +++ b/bindgen-tests/tests/headers/win32-thiscall.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: \-\-rust-target=1.33 -- --target=i686-pc-windows-msvc +// bindgen-flags: --raw-line "#![cfg(not(test))]" -- --target=i686-pc-windows-msvc class Foo { public: diff --git a/bindgen-tests/tests/headers/win32-vectorcall.h b/bindgen-tests/tests/headers/win32-vectorcall.h index 245d97b340..3fe36f1004 100644 --- a/bindgen-tests/tests/headers/win32-vectorcall.h +++ b/bindgen-tests/tests/headers/win32-vectorcall.h @@ -1,3 +1,3 @@ -// bindgen-flags: \-\-rust-target=1.33 -- --target=x86_64-pc-windows-msvc +// bindgen-flags: -- --target=x86_64-pc-windows-msvc int __vectorcall test_vectorcall(int a, int b); diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp index e44b43285a..34faea5d90 100644 --- a/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: \-\-rust-target=1.33 --wrap-unsafe-ops --no-layout-tests +// bindgen-flags: --wrap-unsafe-ops --no-layout-tests template struct TErrorResult { diff --git a/bindgen/codegen/bitfield_unit.rs b/bindgen/codegen/bitfield_unit.rs index 59c66f8cb7..8be311e311 100644 --- a/bindgen/codegen/bitfield_unit.rs +++ b/bindgen/codegen/bitfield_unit.rs @@ -38,6 +38,19 @@ where Self::extract_bit(byte, index) } + #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + + let byte_index = index / 8; + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; + + Self::extract_bit(byte, index) + } + #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { @@ -64,6 +77,19 @@ where *byte = Self::change_bit(*byte, index, val); } + #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + + let byte_index = index / 8; + let byte = unsafe { + (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize) + }; + + unsafe { *byte = Self::change_bit(*byte, index, val) }; + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); @@ -89,6 +115,35 @@ where val } + #[inline] + pub unsafe fn raw_get( + this: *const Self, + bit_offset: usize, + bit_width: u8, + ) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + core::mem::size_of::() + ); + + let mut val = 0; + + for i in 0..(bit_width as usize) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + + val + } + #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); @@ -109,4 +164,32 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } + + #[inline] + pub unsafe fn raw_set( + this: *mut Self, + bit_offset: usize, + bit_width: u8, + val: u64, + ) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + core::mem::size_of::() + ); + + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + unsafe { + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) + }; + } + } } diff --git a/bindgen/codegen/bitfield_unit_raw_ref_macros.rs b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs deleted file mode 100644 index 0c864c7369..0000000000 --- a/bindgen/codegen/bitfield_unit_raw_ref_macros.rs +++ /dev/null @@ -1,191 +0,0 @@ -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} - -impl __BindgenBitfieldUnit { - #[inline] - pub const fn new(storage: Storage) -> Self { - Self { storage } - } -} - -impl __BindgenBitfieldUnit -where - Storage: AsRef<[u8]> + AsMut<[u8]>, -{ - #[inline] - fn extract_bit(byte: u8, index: usize) -> bool { - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - - let mask = 1 << bit_index; - - byte & mask == mask - } - - #[inline] - pub fn get_bit(&self, index: usize) -> bool { - debug_assert!(index / 8 < self.storage.as_ref().len()); - - let byte_index = index / 8; - let byte = self.storage.as_ref()[byte_index]; - - Self::extract_bit(byte, index) - } - - #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - - let byte_index = index / 8; - let byte = unsafe { *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize) }; - - Self::extract_bit(byte, index) - } - - #[inline] - fn change_bit(byte: u8, index: usize, val: bool) -> u8 { - let bit_index = if cfg!(target_endian = "big") { - 7 - (index % 8) - } else { - index % 8 - }; - - let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } - } - - #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { - debug_assert!(index / 8 < self.storage.as_ref().len()); - - let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; - - *byte = Self::change_bit(*byte, index, val); - } - - #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - - let byte_index = index / 8; - let byte = unsafe { - (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize) - }; - - unsafe { *byte = Self::change_bit(*byte, index, val) }; - } - - #[inline] - pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() - ); - - let mut val = 0; - - for i in 0..(bit_width as usize) { - if self.get_bit(i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - - val - } - - #[inline] - pub unsafe fn raw_get( - this: *const Self, - bit_offset: usize, - bit_width: u8, - ) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - core::mem::size_of::() - ); - - let mut val = 0; - - for i in 0..(bit_width as usize) { - if unsafe { Self::raw_get_bit(this, i + bit_offset) } { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - - val - } - - #[inline] - pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() - ); - - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - self.set_bit(index + bit_offset, val_bit_is_set); - } - } - - #[inline] - pub unsafe fn raw_set( - this: *mut Self, - bit_offset: usize, - bit_width: u8, - val: u64, - ) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - core::mem::size_of::() - ); - - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; - } - } -} diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 82172f3488..9b2e5256c3 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -100,7 +100,7 @@ pub(crate) fn blob( if data_len == 1 { ty - } else if ffi_safe && ctx.options().rust_features().min_const_generics { + } else if ffi_safe { ctx.generated_opaque_array(); if ctx.options().enable_cxx_namespaces { syn::parse_quote! { root::__BindgenOpaqueArray<#ty, #data_len> } @@ -139,7 +139,6 @@ pub(crate) mod ast_ty { use crate::ir::function::FunctionSig; use crate::ir::layout::Layout; use crate::ir::ty::{FloatKind, IntKind}; - use crate::RustTarget; use proc_macro2::TokenStream; use std::str::FromStr; @@ -311,60 +310,22 @@ pub(crate) mod ast_ty { } } - pub(crate) fn float_expr( - ctx: &BindgenContext, - f: f64, - ) -> Result { + pub(crate) fn float_expr(f: f64) -> Result { if f.is_finite() { let val = proc_macro2::Literal::f64_unsuffixed(f); return Ok(quote!(#val)); } - let prefix = ctx.trait_prefix(); - let rust_target = ctx.options().rust_target; - if f.is_nan() { - // FIXME: This should be done behind a `RustFeature` instead - #[allow(deprecated)] - let tokens = if rust_target >= RustTarget::Stable_1_43 { - quote! { - f64::NAN - } - } else { - quote! { - ::#prefix::f64::NAN - } - }; - return Ok(tokens); + return Ok(quote! { f64::NAN }); } if f.is_infinite() { let tokens = if f.is_sign_positive() { - // FIXME: This should be done behind a `RustFeature` instead - #[allow(deprecated)] - if rust_target >= RustTarget::Stable_1_43 { - quote! { - f64::INFINITY - } - } else { - quote! { - ::#prefix::f64::INFINITY - } - } + quote! { f64::INFINITY } } else { - // FIXME: This should be done behind a `RustFeature` instead - #[allow(deprecated)] - // Negative infinity - if rust_target >= RustTarget::Stable_1_43 { - quote! { - f64::NEG_INFINITY - } - } else { - quote! { - ::#prefix::f64::NEG_INFINITY - } - } + quote! { f64::NEG_INFINITY } }; return Ok(tokens); } diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 058a73bd13..45394724de 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -1,7 +1,7 @@ use crate::ir::comp::{BitfieldUnit, CompKind, Field, FieldData, FieldMethods}; use crate::ir::context::BindgenContext; use crate::ir::item::{HasTypeParamInArray, IsOpaque, Item, ItemCanonicalName}; -use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; +use crate::ir::ty::TypeKind; use std::fmt::Write as _; pub(crate) fn gen_debug_impl( @@ -173,32 +173,9 @@ impl<'a> ImplDebug<'a> for Item { // Generics are not required to implement Debug if self.has_type_param_in_array(ctx) { Some((format!("{name}: Array with length {len}"), vec![])) - } else if len < RUST_DERIVE_IN_ARRAY_LIMIT || - ctx.options().rust_features().larger_arrays - { + } else { // The simple case debug_print(name, "e! { #name_ident }) - } else if ctx.options().use_core { - // There is no String in core; reducing field visibility to avoid breaking - // no_std setups. - Some((format!("{name}: [...]"), vec![])) - } else { - // Let's implement our own print function - Some(( - format!("{name}: [{{}}]"), - vec![quote! {{ - use std::fmt::Write as _; - let mut output = String::new(); - let mut iter = self.#name_ident.iter(); - if let Some(value) = iter.next() { - let _ = write!(output, "{value:?}"); - for value in iter { - let _ = write!(output, ", {value:?}"); - } - } - output - }}], - )) } } TypeKind::Vector(_, len) => { diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index c2787967d8..a8edb4773d 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -1,7 +1,7 @@ use crate::ir::comp::{CompInfo, CompKind, Field, FieldMethods}; use crate::ir::context::BindgenContext; use crate::ir::item::{IsOpaque, Item}; -use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; +use crate::ir::ty::TypeKind; /// Generate a manual implementation of `PartialEq` trait for the /// specified compound type. @@ -30,15 +30,7 @@ pub(crate) fn gen_partialeq_impl( let ty_item = ctx.resolve_item(base.ty); let field_name = &base.field_name; - - if ty_item.is_opaque(ctx, &()) { - let field_name = ctx.rust_ident(field_name); - tokens.push(quote! { - &self. #field_name [..] == &other. #field_name [..] - }); - } else { - tokens.push(gen_field(ctx, ty_item, field_name)); - } + tokens.push(gen_field(ctx, ty_item, field_name)); } for field in comp_info.fields() { @@ -100,29 +92,9 @@ fn gen_field( TypeKind::Comp(..) | TypeKind::Pointer(_) | TypeKind::Function(..) | + TypeKind::Array(..) | + TypeKind::TemplateInstantiation(..) | TypeKind::Opaque => quote_equals(&name_ident), - - TypeKind::TemplateInstantiation(ref inst) => { - if inst.is_opaque(ctx, ty_item) { - quote! { - &self. #name_ident [..] == &other. #name_ident [..] - } - } else { - quote_equals(&name_ident) - } - } - - TypeKind::Array(_, len) => { - if len <= RUST_DERIVE_IN_ARRAY_LIMIT || - ctx.options().rust_features().larger_arrays - { - quote_equals(&name_ident) - } else { - quote! { - &self. #name_ident [..] == &other. #name_ident [..] - } - } - } TypeKind::Vector(_, len) => { let self_ids = 0..len; let other_ids = 0..len; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 5425962bac..25118f2a89 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -726,7 +726,6 @@ impl CodeGenerator for Var { } else { None }; - if let Some(cstr) = cstr { let cstr_ty = quote! { ::#prefix::ffi::CStr }; if rust_features.literal_cstr { @@ -763,7 +762,7 @@ impl CodeGenerator for Var { } } VarType::Float(f) => { - if let Ok(expr) = helpers::ast_ty::float_expr(ctx, f) { + if let Ok(expr) = helpers::ast_ty::float_expr(f) { result.push(quote! { #(#attrs)* pub const #canonical_ident : #ty = #expr ; @@ -1792,12 +1791,6 @@ impl FieldCodegen<'_> for BitfieldUnit { continue; } - if layout.size > RUST_DERIVE_IN_ARRAY_LIMIT && - !ctx.options().rust_features().larger_arrays - { - continue; - } - let mut bitfield_representable_as_int = true; let mut bitfield_visibility = visibility_kind; bf.codegen( @@ -2005,33 +1998,31 @@ impl<'a> FieldCodegen<'a> for Bitfield { } })); - if ctx.options().rust_features.raw_ref_macros { - methods.extend(Some(quote! { - #[inline] - #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty { - unsafe { - ::#prefix::mem::transmute(<#unit_field_ty>::raw_get( - (*::#prefix::ptr::addr_of!((*this).#unit_field_ident)).as_ref() as *const _, - #offset, - #width, - ) as #bitfield_int_ty) - } + methods.extend(Some(quote! { + #[inline] + #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty { + unsafe { + ::#prefix::mem::transmute(<#unit_field_ty>::raw_get( + (*::#prefix::ptr::addr_of!((*this).#unit_field_ident)).as_ref() as *const _, + #offset, + #width, + ) as #bitfield_int_ty) } + } - #[inline] - #access_spec unsafe fn #raw_setter_name(this: *mut Self, val: #bitfield_ty) { - unsafe { - let val: #bitfield_int_ty = ::#prefix::mem::transmute(val); - <#unit_field_ty>::raw_set( - (*::#prefix::ptr::addr_of_mut!((*this).#unit_field_ident)).as_mut() as *mut _, - #offset, - #width, - val as u64, - ) - } + #[inline] + #access_spec unsafe fn #raw_setter_name(this: *mut Self, val: #bitfield_ty) { + unsafe { + let val: #bitfield_int_ty = ::#prefix::mem::transmute(val); + <#unit_field_ty>::raw_set( + (*::#prefix::ptr::addr_of_mut!((*this).#unit_field_ident)).as_mut() as *mut _, + #offset, + #width, + val as u64, + ) } - })); - } + } + })); } else { methods.extend(Some(quote! { #[inline] @@ -2057,8 +2048,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { } })); - if ctx.options().rust_features.raw_ref_macros { - methods.extend(Some(quote! { + methods.extend(Some(quote! { #[inline] #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty { unsafe { @@ -2083,7 +2073,6 @@ impl<'a> FieldCodegen<'a> for Bitfield { } } })); - } } } } @@ -2401,7 +2390,6 @@ impl CodeGenerator for CompInfo { self.already_packed(ctx).unwrap_or(false)) { let n = layout.map_or(1, |l| l.align); - assert!(ctx.options().rust_features().repr_packed_n || n == 1); let packed_repr = if n == 1 { "packed".to_string() } else { @@ -2761,21 +2749,11 @@ impl CodeGenerator for CompInfo { if needs_default_impl { let prefix = ctx.trait_prefix(); - let body = if ctx.options().rust_features().maybe_uninit { - quote! { - let mut s = ::#prefix::mem::MaybeUninit::::uninit(); - unsafe { - ::#prefix::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } - } else { - quote! { - unsafe { - let mut s: Self = ::#prefix::mem::uninitialized(); - ::#prefix::ptr::write_bytes(&mut s, 0, 1); - s - } + let body = quote! { + let mut s = ::#prefix::mem::MaybeUninit::::uninit(); + unsafe { + ::#prefix::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() } }; // Note we use `ptr::write_bytes()` instead of `mem::zeroed()` because the latter does @@ -3096,24 +3074,11 @@ impl Method { // variable called `__bindgen_tmp` we're going to create. if self.is_constructor() { let prefix = ctx.trait_prefix(); - let tmp_variable_decl = if ctx - .options() - .rust_features() - .maybe_uninit - { - exprs[0] = quote! { - __bindgen_tmp.as_mut_ptr() - }; - quote! { - let mut __bindgen_tmp = ::#prefix::mem::MaybeUninit::uninit() - } - } else { - exprs[0] = quote! { - &mut __bindgen_tmp - }; - quote! { - let mut __bindgen_tmp = ::#prefix::mem::uninitialized() - } + exprs[0] = quote! { + __bindgen_tmp.as_mut_ptr() + }; + let tmp_variable_decl = quote! { + let mut __bindgen_tmp = ::#prefix::mem::MaybeUninit::uninit() }; stmts.push(tmp_variable_decl); } else if !self.is_static() { @@ -3130,14 +3095,8 @@ impl Method { stmts.push(call); if self.is_constructor() { - stmts.push(if ctx.options().rust_features().maybe_uninit { - quote! { + stmts.push(quote! { __bindgen_tmp.assume_init() - } - } else { - quote! { - __bindgen_tmp - } }); } @@ -5373,12 +5332,7 @@ pub(crate) mod utils { return; } - let bitfield_unit_src = if ctx.options().rust_features().raw_ref_macros - { - include_str!("./bitfield_unit_raw_ref_macros.rs") - } else { - include_str!("./bitfield_unit.rs") - }; + let bitfield_unit_src = include_str!("./bitfield_unit.rs"); let bitfield_unit_src = if true { Cow::Borrowed(bitfield_unit_src) } else { diff --git a/bindgen/features.rs b/bindgen/features.rs index 45ea893947..04450bdee5 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -327,16 +327,8 @@ define_rust_targets! { Stable_1_71(71) => { c_unwind_abi: #106075 }, Stable_1_68(68) => { abi_efiapi: #105795 }, Stable_1_64(64) => { core_ffi_c: #94503 }, - Stable_1_51(51) => { - raw_ref_macros: #80886, - min_const_generics: #74878, - }, Stable_1_59(59) => { const_cstr: #54745 }, - Stable_1_47(47) => { larger_arrays: #74060 }, - Stable_1_43(43) => { associated_constants: #68952 }, - Stable_1_40(40) => { non_exhaustive: #44109 }, - Stable_1_36(36) => { maybe_uninit: #60445 }, - Stable_1_33(33) => { repr_packed_n: #57049 }, + Stable_1_51(51) => {}, } /// Latest stable release of Rust that is supported by bindgen @@ -477,11 +469,11 @@ mod test { #[test] fn release_versions_for_editions() { assert_eq!( - "1.33".parse::().unwrap().latest_edition(), + "1.51".parse::().unwrap().latest_edition(), RustEdition::Edition2018 ); assert_eq!( - "1.56".parse::().unwrap().latest_edition(), + "1.59".parse::().unwrap().latest_edition(), RustEdition::Edition2021 ); assert_eq!( diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index eaa20fff46..b1f167fb6c 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -489,12 +489,8 @@ impl DeriveTrait { } } - fn can_derive_large_array(self, ctx: &BindgenContext) -> bool { - if ctx.options().rust_features().larger_arrays { - !matches!(self, DeriveTrait::Default) - } else { - matches!(self, DeriveTrait::Copy) - } + fn can_derive_large_array(self, _: &BindgenContext) -> bool { + !matches!(self, DeriveTrait::Default) } fn can_derive_union(self) -> bool { diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 0b50bf3244..c67f9a2597 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1782,7 +1782,11 @@ impl DotAttributes for CompInfo { impl IsOpaque for CompInfo { type Extra = Option; - fn is_opaque(&self, ctx: &BindgenContext, layout: &Option) -> bool { + fn is_opaque( + &self, + ctx: &BindgenContext, + _layout: &Option, + ) -> bool { if self.has_non_type_template_params || self.has_unevaluable_bit_field_width { @@ -1813,23 +1817,6 @@ impl IsOpaque for CompInfo { return true; } - if !ctx.options().rust_features().repr_packed_n { - // If we don't have `#[repr(packed(N)]`, the best we can - // do is make this struct opaque. - // - // See https://github.com/rust-lang/rust-bindgen/issues/537 and - // https://github.com/rust-lang/rust/issues/33158 - if self.is_packed(ctx, layout.as_ref()) && - layout.is_some_and(|l| l.align > 1) - { - warn!("Found a type that is both packed and aligned to greater than \ - 1; Rust before version 1.33 doesn't have `#[repr(packed(N))]`, so we \ - are treating it as opaque. You may wish to set bindgen's rust target \ - version to 1.33 or later to enable `#[repr(packed(N))]` support."); - return true; - } - } - false } }